2015-06-25 50 views
0

我有以下副本將傳遞到PowerPoint幻燈片的圖表複製。它用於從Excel電子表格中的圖表和數據構建PowerPoint套牌。此代碼在Excel 2010中工作得很好。我剛剛升級到Office 2013,現在我在sr.LockAspectRatio = msoFalse行上收到「Object Required」錯誤。升級到Office 2013之後的對象所需的錯誤

Sub Copy_Chart(PPRes As PowerPoint.Presentation, SlideNumber As Integer, Chart As ChartObject, Top As Single, Left As Single, Height As Single, Width As Single) 

    Dim sr As PowerPoint.ShapeRange 
    Chart.Activate 
    ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture 
    Set sr = PPRes.Slides(SlideNumber).Shapes.Paste 
    sr.LockAspectRatio = msoFalse 

    sr.Top = Top 
    sr.Left = Left 
    sr.Height = Height 
    sr.Width = Width 

End Sub 
+0

如果你通過'sr'設置得當嗎? – Raystafarian

+0

我會說不。我可以確認該對象正在粘貼到PowerPoint演示文稿中。所以,我猜測'Paste()'操作不能再返回形狀範圍...... – jradich1234

+0

對於PowerPoint 2013的幫助顯示[Paste method](https://msdn.microsoft.com/EN -US/library/office/ff745532.aspx)返回一個ShapeRange對象 – barrowc

回答

1

顯然Past方法必須返回一個ShapeRanges數組。我不確定這是不是一直如此,Office 2010更寬容一點。所以,要糾正這個問題,當引用sr我不得不這樣做,像sr(sr.Count)。下面的工作代碼...

Sub Copy_Chart(PPRes As PowerPoint.Presentation, SlideNumber As Integer, Chart As ChartObject, Top As Single, Left As Single, Height As Single, Width As Single) 

    Dim sr As PowerPoint.ShapeRange 
    Chart.Activate 
    ActiveChart.CopyPicture Appearance:=xlScreen, Size:=xlScreen, Format:=xlPicture 
    Set sr = PPRes.Slides(SlideNumber).Shapes.Paste 
    sr(sr.Count).LockAspectRatio = msoFalse 

    sr(sr.Count).Top = Top 
    sr(sr.Count).Left = Left 
    sr(sr.Count).Height = Height 
    sr(sr.Count).Width = Width 

End Sub