2013-10-09 45 views
0

我想的圖像粘貼到PowerPoint幻燈片,然後調整一次我把它粘貼,粘貼和調整Excel VBA中

我不知道像IDEX所以它需要能夠立即調整afterr被粘貼

下面不工作,請誰能幫

Sub PasteOnSlide() 

Dim strPresPath As String 
strPresPath = "c://myfile" 
Set oPPTFile = oPPTApp.Presentations.Open(strPresPath) 

oPPTFile.Slides(4).Shapes.PasteSpecial(ppPasteEnhancedMetafile).select 

With Selection 
    .Height = 270 
    .Width = 680 
    .Left = 20 
    .Top = 120 
    .ZOrder msoSendToBack 
End With 

End Sub 

我也嘗試:

set MyShape = oPPTFile.Slides(4).Shapes.PasteSpecial(ppPasteEnhancedMetafile).select 
With MyShape 
    .Height = 270 
    .Width = 680 
    .Left = 20 
    .Top = 120 
    .ZOrder msoSendToBack 
End With 

End Sub 
+0

您已經激活了Microsoft PowerPoint XX.X對象庫?如果是這樣,你會得到什麼錯誤? – L42

回答

0

哦,如此接近......

避免期運用Select,(並聲明所有的變量!)

Sub PasteOnSlide() 
    Dim strPresPath As String 
    Dim MyShape As Shape 
    Dim oPPTFile As Presentation 
    Dim oPPTApp As Application 

    Set oPPTApp = Application 
    strPresPath = "c://myfile" 
    Set oPPTFile = oPPTApp.Presentations.Open(strPresPath) 

    Set MyShape = oPPTFile.Slides(4).Shapes.PasteSpecial(ppPasteEnhancedMetafile).Item(1) 

    With MyShape 
     .Height = 270 
     .Width = 680 
     .Left = 20 
     .Top = 120 
     .ZOrder msoSendToBack 
    End With 
End Sub 

您應該添加錯誤處理,包括覆蓋的情況下沒有什麼剪貼板粘貼,或者strPresPath未指向現有演示文件文件。