复制绘图区域在 Powerpoint VBA 中无法正常工作

2023-11-30

我拼凑了以下代码,将图表的格式从一个图表复制到另一个图表。代码仍然很混乱,因为我试图想出引用图表的最佳方法(欢迎任何想法!)。

我无法准确复制主要是绘图区域和辅助访问的格式和位置。

一个页面上必须有两个图表,首先选择源,然后选择目标。目前来看,它们应该是同一类型。

感谢您的帮助。

Sub CopyChartFormat()

' Define the source and destination charts
Dim sourceChart As Chart
Dim destChart As Chart

'Check if two charts are selected
If ActiveWindow.Selection.Type <> ppSelectionShapes Then
    MsgBox "Please select two charts."
    Exit Sub
End If

If ActiveWindow.Selection.ShapeRange.Count <> 2 Then
    MsgBox "Please select two charts."
    Exit Sub
End If

Set sourceChart = ActiveWindow.Selection.ShapeRange(1).Chart
Set destChart = ActiveWindow.Selection.ShapeRange(2).Chart
    
''    If .HasChart = True Then
''    End If

    '' Chart size
    ActiveWindow.Selection.ShapeRange(2).Width = ActiveWindow.Selection.ShapeRange(1).Width
    ActiveWindow.Selection.ShapeRange(2).Height = ActiveWindow.Selection.ShapeRange(1).Height
    
'' Adjust plot area size and fill

    With destChart.PlotArea
        .Top = sourceChart.PlotArea.Top
        .Left = sourceChart.PlotArea.Left
        .Height = sourceChart.PlotArea.Height
        .Width = sourceChart.PlotArea.Width
    
''        .Format.Fill.ForeColor.RGB = sourceChart.PlotArea.Format.Fill.ForeColor.RGB
''        .Format.Line.ForeColor.RGB = sourceChart.PlotArea.Format.Line.ForeColor.RGB
    
    
    End With


End Sub

你错过了情节区域的内部。我添加了尽可能多的东西。我测试过,如果字体大小不同,我必须运行两次才能得到想要的结果。


Sub CopyChartFormat()

' Define the source and destination charts
Dim sourceChart As Chart
Dim destChart As Chart

'Check if two charts are selected
If ActiveWindow.Selection.Type <> ppSelectionShapes Then
    MsgBox "Please select two charts."
    Exit Sub
End If

If ActiveWindow.Selection.ShapeRange.Count <> 2 Then
    MsgBox "Please select two charts."
    Exit Sub
End If

Set sourceChart = ActiveWindow.Selection.ShapeRange(1).Chart
Set destChart = ActiveWindow.Selection.ShapeRange(2).Chart
    
''    If .HasChart = True Then
''    End If

    '' Chart size
    ActiveWindow.Selection.ShapeRange(2).Width = ActiveWindow.Selection.ShapeRange(1).Width
    ActiveWindow.Selection.ShapeRange(2).Height = ActiveWindow.Selection.ShapeRange(1).Height
    
'' Adjust plot area size and fill

    With destChart.PlotArea
        .Top = sourceChart.PlotArea.Top
        .Left = sourceChart.PlotArea.Left
        .Height = sourceChart.PlotArea.Height
        .Width = sourceChart.PlotArea.Width
        
        
        .InsideWidth = sourceChart.PlotArea.InsideWidth
        .InsideHeight = sourceChart.PlotArea.InsideHeight
        .InsideLeft = sourceChart.PlotArea.InsideLeft
        .InsideTop = sourceChart.PlotArea.InsideTop

        End With
        
        With destChart.Format
        .TextFrame2.TextRange.Font.Size = sourceChart.Format.TextFrame2.TextRange.Font.Size
        .TextFrame2.TextRange.Font.Name = sourceChart.Format.TextFrame2.TextRange.Font.Name
        End With
        
        

''        .Format.Fill.ForeColor.RGB = sourceChart.PlotArea.Format.Fill.ForeColor.RGB
''        .Format.Line.ForeColor.RGB = sourceChart.PlotArea.Format.Line.ForeColor.RGB
    
    
'    End With
    
    With destChart.ChartTitle.Format
            .TextFrame2.TextRange.Font.Size = sourceChart.ChartTitle.Format.TextFrame2.TextRange.Font.Size
    End With
    
    With destChart.ChartArea.Format
    
        .TextFrame2.TextRange.Font.Size = sourceChart.ChartArea.Format.TextFrame2.TextRange.Font.Size
        
    End With
    
    
    With destChart.Legend
        .Position = sourceChart.Legend.Position
        .Left = sourceChart.Legend.Left
        .Top = sourceChart.Legend.Top
        .Width = sourceChart.Legend.Width
        .Height = sourceChart.Legend.Height
    End With


'With destChart.Floor   'commented out as i keep on getting "Method failed"
'
'.Format.TextFrame2.TextRange.Font.Size = sourceChart.Floor.Format.TextFrame2.TextRange.Font.Size
'
'End With

With destChart.Format
.TextFrame2.TextRange.Font.Size = sourceChart.Format.TextFrame2.TextRange.Font.Size

End With


End Sub
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

复制绘图区域在 Powerpoint VBA 中无法正常工作 的相关文章

  • VBA Excel:将范围值分配给新范围

    我在将一个工作簿范围中的值分配给当前工作簿中的某个范围时遇到问题 当我使用 Range A1 C1 分配我的范围时 此代码工作正常 但是当我使用 Range Cells 1 1 Cells 1 3 定义我的范围时 该函数会失败 Sub Co
  • 如何修复日期过滤器 VBA,因为它没有拾取我范围内的所有日期

    我正在尝试创建一个过滤器来过滤掉我选择的日期内的所有日期 我选择的日期将始终反映整个月 例如 如果我需要 2019 年 5 月的数据 我将输入开始日期为 01 05 2019 结束日期为 31 05 2019 我的数据过滤器将需要选取经过我
  • Access / Word 2010 VBA 邮件合并尝试打开 [文件夹名称].mdb 而不是 ACCDB 源

    我们正在尝试从 Access 中自动执行邮件合并过程 单击按钮后 VBA 将运行指定当前数据库 accdb 作为数据源并运行 SQL 具体代码如下 Set up Word Dim objWord As Object Set objWord
  • 如何隐藏组合框下拉列表中的列?

    我正在 Excel 用户窗体中构建一个 ComboBox 该用户窗体从 Access 表中获取其行 我想在下拉列表中向用户显示多个文本字段 但从 ComboBox 返回的值应该是与用户选择的行关联的 ID 号 即 ID 列是绑定列 但我不想
  • 将用户定义的表类型从 VBA 传递到 SQL

    我的任务是创建一个 Excel 电子表格作为 SQL 数据库的前端 以及一些对数据执行复杂计算的 C 我的老板想要前端作为电子表格 而计算对于 VBA 来说似乎太复杂了 目前 检索数据集的存储过程运行良好 然后 用户将在 Excel 中编辑
  • 在用户窗体终止/关闭 VBA 时调用数组

    我有一个问题 我想在用户窗体关闭时将用户窗体的内容存储在数组中 我认为我的语法正确 但似乎不会在用户窗体初始化时重新填充 我尝试将数组放入其自己的模块中 但这也不起作用 有人愿意启发我吗 示例代码 Public Sub DPArrayStu
  • 了解从 MsgBox 返回的响应代码

    我对编程很陌生 我刚刚开始学习 VBA 和 Excel 我在这个网站上遇到并做了这里的例子 但我对这段代码有疑问 我知道变量是使用 Dim 语句声明的 Message 这里是数据类型为整数的变量 我不太明白的是 这里的 6 和 7 是什么意
  • VBA 中的 If 和 Or 多个语句

    我想将包含 14 列的 Excel 文件重新分配到正确的列 包含 12 000 行 为此 我必须使用一些 If And Or 语句将数字放入矩阵中 但显然我没有从中得到正确的东西 它使我的所有单元格为零 而具有值的单元格应保留该值 我哪里出
  • 从 Excel VBA 调用 Bloomberg BQL 查询

    出于复杂的原因 我想在 VBA 中自动调用 Bloomi BQL 查询 我正在从 VBA 脚本更改 Excel 工作表中 BQL Query 公式的输入 并调用 Application Calculate 来运行查询 显示更改为 N A 请
  • VBA复制单元格值和格式

    我如何修改以下代码以便不仅复制值而且复制字体样式 例如大胆或不大胆 谢谢 Private Sub CommandButton1 Click Dim i As Integer Dim a As Integer a 15 For i 11 To
  • SQL查询从表的每条记录生成多条记录

    我有一个包含 3000 条记录的表 使用其中的每一条记录 我必须生成大约 200 条记录 总共 600k 条记录 并通过 SQL Server 2012 将它们插入到第二个表中 我尝试使用 VBA 执行此操作 从第一个表中选择数据 计算 然
  • 调用 UDF 时公式中使用的值的数据类型错误

    我一直在努力找出这里出了什么问题 我有两个包含字符串值的列 我使用第三列调用工作表中的 UDF 但最终得到 Value 并出现错误 公式中使用的值的数据类型错误 Eg Col I Col J File1 Y File1 N File2 Y
  • 我需要使用 VBA 将数据从 Excel 插入 SQL Server

    我需要插入test vba xlsx将数据写入 SQL Server 到特定数据库 Sub insertion Dim conn As ADODB Connection Dim rs As ADODB Recordset Dim sConn
  • 如何从Excel调用VBA函数

    我有一个 excel 文件 我必须在其中放置验证规则 我有一个单元格表示 客户时间 用户可以在其中输入时间 但它是自定义时间 用户可以这样输入时间 23 45 98 20 100 30 用户不能输入字符串 并且不能输入除冒号之外的特殊字符
  • 在Excel中过滤后打印可见区域的宏

    我有一个根据过滤表的宏column A价值观 现在我想打印only过滤器后的可见行 但遗憾的是它打印了所有行 包括过滤期间隐藏的顶部和底部行 在我的工作表中 有来自的数据Column A I 但打印区域只能是Columns C I 过滤后的
  • VBA按空格分割字符串

    我想要一个 Excel 函数 我可以调用该函数并将单元格传递到其中 输入 Firstname Lastname email protected cdn cgi l email protection Firstname midname Las
  • 使用VBA删除Excel中的非重复数据

    我尝试删除非重复数据并保留重复数据 我已经完成了一些编码 但什么也没发生 哦 这是错误 哈哈 这是我的代码 Sub mukjizat2 Dim desc As String Dim sapnbr As Variant Dim shortDe
  • 在没有加载项的情况下加载 Excel

    All 我编写了一个电子表格应用程序 用户通过双击我提供的图标来加载它 问题是用户有很多插件 这会降低 Excel 的速度 如何使用命令行开关加载 Excel 来禁用所有加载项 该问题适用于 Excel 2003 和 Excel 2007
  • 解析未完全加载 VBA 的网站

    尝试进行简单的网络解析 我的问题是页面在向下滚动之前无法完全加载 谷歌搜索已经提出可能使用硒 但由于我不知道如何使用它 我想我会在这里问 我使用的代码 Sub gfquote Dim oHttp As MSXML2 XMLHTTP Dim
  • 如何通过VBA代码修复仅在Excel共享模式下发生的运行时错误400

    我真的不知道400错误是什么原因造成的 下面的代码在正常模式下运行得很好 但是一旦我在共享模式下启用 Excel 并尝试使用用户表单 它就会给我 VBA 400 我在这里尝试做的是在向用户显示用户表单后更改形状的文本并禁用其 OnActio

随机推荐