我有一些代码在 excel 中获取图表并将其粘贴到 powerpoint 幻灯片中。但是,一旦它被粘贴到 powerpoint 我不知道如何调整图表的大小。我已经研究过它是哪个数字“形状”,我可以手动执行此操作,但我不知道如何自动执行此操作。任何帮助将不胜感激,谢谢!
这是我的代码:
Sub AddChartToPPT(PPT As PowerPoint.Application, Slide As Integer, Chart As String, FromTop As Double, FromLeft As Double, Length As Double, Width As Double)
Dim activeslide As PowerPoint.Slide
PPT.ActiveWindow.View.GotoSlide Slide
Set activeslide = PPT.ActivePresentation.Slides(Slide)
ActiveSheet.ChartObjects(Chart).Activate
ActiveChart.ChartArea.Copy
activeslide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture).Select
PPT.ActiveWindow.Selection.ShapeRange.Left = FromLeft
PPT.ActiveWindow.Selection.ShapeRange.Top = FromTop
'Need to add scaling code
End Sub
最佳答案
尝试这个:
dim shp as Object
set shp=activeslide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture)
shp.Left = FromLeft
shp.Top = FromTop
所以你的代码的其余部分:
Sub AddChartToPPT(PPT As PowerPoint.Application, Slide As Integer, Chart As String, FromTop As Double, FromLeft As Double, Length As Double, Width As Double)
Dim activeslide As PowerPoint.Slide, shp as Object
PPT.ActiveWindow.View.GotoSlide Slide
Set activeslide = PPT.ActivePresentation.Slides(Slide)
ActiveSheet.ChartObjects(Chart).Activate
ActiveChart.ChartArea.Copy
set shp=activeslide.Shapes.PasteSpecial(DataType:=ppPasteMetafilePicture)
shp.Left = FromLeft
shp.Top = FromTop
'Need to add scaling code
End Sub
关于excel - 从excel(Excel VBA)插入后在PowerPoint中调整图表大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12983768/