2017-03-06 390 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