2017-03-06 385 views
2

在Excel 2010中使用VBA我可以通过传递文件的URL位置在SharePoint上打开PowerPoint文件。如果我没有登录,它会提示我输入凭据,以便打开它。使用Excel中的Excel VBA 2016打开PowerPoint文件

但是,在Excel 2016中,当我收到在SharePoint上打开Excel文件的提示时,我在打开PowerPoint文件时没有得到提示。相反,我只是得到运行时错误“-2147467259(80004005)”,意思是未经过身份验证。如果我先登录到SharePoint,然后运行它打开的宏,但我不想那样做。有关如何将提示恢复为PowerPoint的任何建议?

Sub OpenPowerPointFile() 
    Dim objPPT As PowerPoint.Application 
    Dim objPres As Object 
    Set objPPT = CreateObject("Powerpoint.Application") 
    objPPT.Visible = True 

    Set objPres = objPPT.Presentations.Open("https://spsite.com/report_template.pptx") 

End Sub 
+0

从我看到的这一点来看,错误与创建简报对象有关。我不确定它是否与引用相关,但是我只是想尝试打开一个powerpoint应用程序而得到错误429。 – Cyril

+0

在我的情况下,我已将“dim objPPT As PowerPoint.Application”修改为“Dim objPPT As Object”,然后PowerPoint打开状态良好,但我无法从网站打开该文件。对不起,我只能提供帮助 –

+0

由于每个站点,列表,文件夹等都具有特定的用户权限,因此可能很难跳过SharePoint中的身份验证过程。您是否尝试过使用WebDAV地址将文档库映射到驱动器盘符以访问代码中的库?这里有一个类似的问题:http://stackoverflow.com/questions/12217680/open-sharepoint-excel-files-with-vba – BWMustang13

回答

0

我能够通过打开文件,通过寻找特定的文件名全部打开PPT文档循环,然后将其分配给对象变量来解决这个问题。

Private Function openPowerPointPresentationFromURL(filePath As String, fileName As String) As PowerPoint.Presentation 

    Dim ppProgram As PowerPoint.Application 
    Dim ppCount As Integer 
    Dim i As Integer 

    On Error GoTo ErrHandler 

    ' Open the file 
    ThisWorkbook.FollowHyperlink (filePath)   

    ' Set the object by looping through all open PPT files and look for the passed file name 
    Set ppProgram = GetObject(, "PowerPoint.Application")    
    ppCount = ppProgram.Presentations.Count 
    For i = 1 To ppCount + 1 
     If ppProgram.Presentations.Item(i).Name = fileName Then 
      Set openPowerPointPresentationFromURL = ppProgram.Presentations.Item(i) 
      Exit Function 
     End If 
    Next i 
    On Error GoTo 0 

ErrHandler: 
    MsgBox "There was an error opening the PowerPoint template that is required for this report." 
    On Error GoTo 0 

End Function