【发布时间】:2022-01-26 20:59:31
【问题描述】:
我在 excel 工作簿中每个工作表一个图表和多个工作表,我正在尝试将所有图表作为图片导出到 PowerPoints 问题是我当前的代码不起作用 我的代码错误:
-
PowerPoint 按预期打开
-
复制我在运行之前选择的活动表的图表
-
复制的图表粘贴到 PowerPoint 中
-
PowerPoint 创建下一张幻灯片
-
现在再次复制来自同一张表的同一张图表的问题!我希望代码移动到下一张表,选择上面的图表,然后在下一张幻灯片中复制过去!
子 TEST_ExportChartsToPowerPoint_SingleWorkbook() '声明 PowerPoint 对象变量 将 pptApp 调暗为 PowerPoint.Application 将 pptPres 调暗为 PowerPoint.Presentation 将 pptSlide 调暗为 PowerPoint.Slide 将 SldIndex 调暗为整数 '声明 Excel 对象变量 将 Chrt 调暗为 ChartObject '将 Chrt 调暗为 ChartArea 将 WrkSht 调暗为工作表
'Create a new instance of PowerPoint Set pptApp = New PowerPoint.Application pptApp.Visible = True 'Create a new Presentation within the PowerPoint Application Set pptPres = pptApp.Presentations.Add 'Create an index handler for the slide creation SldIndex = 1 'Loop through all of the worksheets in the active work book For Each WrkSht In Worksheets 'WrkSht.Select ActiveChart.ChartArea.Select ActiveChart.ChartArea.Copy 'Create a new slide, set the layout to blank, and paste the chart on the slide Set pptSlide = pptPres.Slides.Add(SldIndex, ppLayoutBlank) pptSlide.Shapes.Paste 'Increment our slide index SldIndex = SldIndex + 1 Next WrkSht结束子
【问题讨论】:
-
这里有问题吗?
-
问题是我当前的代码不起作用
-
我做了一个快速测试,代码对我有用。请准确描述发生了什么:您是否收到运行时错误? PowerPoint 是否打开?是否创建了幻灯片?活动工作簿是否有一些图表?您是否调试过代码以查看失败的地方?
-
它代替做什么?运行代码时会发生什么? “我的代码不起作用”并不是对实际发生的情况非常有用的描述。
-
1. PowerPoint 按预期打开 2. 我在运行之前选择的活动工作表的图表被复制 3. 复制的图表被粘贴到 PowerPoint 4. PowerPoint 创建下一张幻灯片 现在问题来自同一张工作表的相同图表被复制再次!我希望代码移动到下一张表,选择上面的图表,然后在下一张幻灯片中复制过去!
标签: excel vba powerpoint excel-charts