2017-08-03 136 views
-1

我有一个脚本通过调用创建特定幻灯片的宏来创建PowerPoint演示文稿。但是,对于演示的一部分,我需要从最后一个演示文稿中抓取幻灯片并将其复制到新演示文稿中。但是当我打开演示文稿时,出现错误:对象演示文稿的方法“打开”失败。我如何解决这个问题?VBA的PowerPoint错误打开

Sub CreateNewPresentation() 

    Dim ppApp As PowerPoint.Application 
    Dim ppPres As PowerPoint.Presentation 
    Dim slidesCount As Long 

    On Error Resume Next 
    Set ppApp = GetObject(, "PowerPoint.Application") 
    On Error GoTo 0 

    If ppApp Is Nothing Then 
    Set ppApp = New PowerPoint.Application 
    End If 

    Set ppPres = ppApp.Presentations.Add 
    ppApp.Visible = True 
    slidesCount = ppPres.Slides.Count 
    Call create_Views_Slide(slidesCount, ppPres, ppApp) 
End sub 

sub create_Views_Slide(sldNum As Long, ppPrez As PowerPoint.Presentation, ppt As PowerPoint.Application) 
    Dim myFilePath As String, myFileName As String, myFile As String 
    Dim ppSlide As PowerPoint.Slide 
    Dim objPres As PowerPoint.Presentation 
    Set ppSlide = ppPrez.Slides.Add(sldNum + 1, ppLayoutBlank) 
    ppPrez.PageSetup.SlideSize = ppSlideSizeLetterPaper 
    myFile="File path....." 
    Set objPres = ppt.Presentations.Open(myFile) 
    objPres.Slides(1).Copy 
    ppPrez.Slides.Paste Index:=1 
    objPres.Close 

End Sub 

回答

1

(发布代表OP)的

我的文件路径字符串错了。