[英]Resizing chart in powerpoint after inserting it from excel (Excel VBA)
我有一些代碼在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
根據我的經驗,在將圖表對象粘貼到PowerPoint之前,可以更輕松地在Excel中調整圖表對象的大小。 首先,Excel的對象模型更清晰。 其次,調整元文件的大小可能會導致失真,同時調整圖表大小並粘貼為不需要調整大小的元文件也不會。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.