2012-10-19 218 views
1

我有一些代碼需要中的圖表並將其粘貼到幻燈片中。但是,一旦它被粘貼到我不知道如何調整圖表大小。我研究過查找哪個數字是「形狀」,我​​可以手動執行此操作,但我不知道如何自動執行此操作。任何幫助將不勝感激,謝謝!從excel中插入後在powerpoint中調整圖表(Excel VBA)

這裏是我的代碼:

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 

回答

2

試試這個:

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 
+0

嗯,這似乎不工作。此外,您的代碼似乎是針對圖表的位置(我已經擁有),而不是圖表的大小。 – Andrew

+0

使用.width和.height – nutsch

+0

什麼似乎不起作用?你有錯誤信息嗎? – nutsch

2

根據我的經驗,它更容易調整在Excel中將圖表對象粘貼到PowerPoint中之前。首先,Excel的對象模型更清晰。其次,調整元文件的大小可能會導致失真,同時調整圖表大小並粘貼爲不需要調整大小的元文件不會。