2013-10-09 43 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未指向现有演示文件文件。