【发布时间】:2018-04-24 15:05:18
【问题描述】:
我已经有一个脚本可以复制图表:
'Do the following:
Set wrkbk = ActiveWorkbook
' Load up the PowerPoint template
Set objPPT = CreateObject("Powerpoint.application")
objPPT.Visible = True
objPPT.Presentations.Open Filename:="path\to\template.pptx", ReadOnly:=msoTrue
objPPT.ActiveWindow.ViewType = 1 'ppViewSlide
' Variable defs
Dim wrksht As Worksheet
Dim chart As Object
Dim pastedChart As Object
' We're only going to copy from the current worksheet
Set wrksht = ActiveSheet
Set chart = wrksht.ChartObjects(1).chart ' We'll just use the default chart
' Now we select and copy the chart...
chart.ChartArea.Select
chart.ChartArea.Copy
With Selection
' Open up the active slide and paste into it
Set pastedChart = objPPT.ActiveWindow.View.Slide.Shapes.Paste
' ' In earlier versions of excel, we needed to be a lot more specific ...
' objPPT.ActiveWindow.View.Slide.Shapes.PasteSpecial Link:=False, DataType:=wdPasteEnhancedMetafile, _
' Placement:=wdInLine, DisplayAsIcon:=False
' The default paste is a little overscaled. Scale it down.
' See:
' https://msdn.microsoft.com/en-us/VBA/PowerPoint-VBA/articles/shape-scaleheight-method-powerpoint
pastedChart.ScaleHeight 0.9, msoFalse, msoScaleFromMiddle
End With
这很好用,而且我还有一个脚本可以将其推广到工作簿中的所有工作表。
但是,粘贴的图表对象仍然引用源 Excel 文件。显然,图表可以完全包含在 PowerPoint 中(因为您可以仅在其中创建图表);问题是,我可以这样做并使 PPTX 独立吗?
我最好的猜测是它与the DataTable attribute 有关,但仅此而已。
【问题讨论】:
标签: vba excel powerpoint