Sub printDashboard()
Dim sheet1 As Excel.Worksheet
Set sheet1 = ActiveWorkbook.Sheets("PM Dashboard")
Dim pptChart2 As Excel.ChartObject
'Open PowerPoint template
Dim sPath As String
sPath = ActiveWorkbook.Path
Dim pp As PowerPoint.Application, pps As PowerPoint.Presentation
Set pp = New PowerPoint.Application
pp.Visible = True
Set pps = pp.Presentations.Open(sPath & "\template_Slides.pptx")
Dim firstSlide As PowerPoint.Slide
Set firstSlide = pps.Slides(1)
'Paste the second chart
Set pptChart2 = sheet1.ChartObjects("chartPM2")
pptChart2.Copy
Dim myShape2 As Object
Set myShape2 = firstSlide.Shapes.PasteSpecial()
'myShape2.Chart.ApplyChartTemplate (sPath & "\pipelineManagementChartFormat.crtx")
With myShape2
.Top = 1.52 * 72
.Left = 5.33 * 72
.Width = 4.08 * 72
.Height = 2.6 * 72
End With
End Sub
所以这段代码完全在它:VBA - 如何粘贴Excel图表后应用图表模板到PowerPoint
- 正确打开
- Excel图表粘贴在PowerPoint文件并调整大小/重新定位
但是,我无法弄清楚如何应用一个保存的图表模板,我已经在同一目录。您可以看到我试图通过在“粘贴第二个图表”部分注释掉的“ApplyChartTemplate”行来完成此操作。
我很感谢这里的任何帮助。我已经尝试了许多不同的方法,将图表模板粘贴到幻灯片后应用。我还没有取得任何成功。
由于
的.ApplyChartTemplate方法的工作原理,以便为它注释掉了,因为它没有做任何事情,或者因为它抛出一个错误,如果以后,哪个错误? –
如果我取消注释,我收到“运行时错误445:对象不支持此操作” – bounty252