从SharePoint使用Excel VBA 2016打开Powerpoint文件

pheeper

在Excel 2010中使用VBA,我可以通过传递文件的URL位置在SharePoint上打开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
pheeper

通过打开文件,遍历所有打开的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

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章