Forum Discussion
Working with workbooks shared via Teams/Sharepoint
Thank You NikolinoDE
How can I make the ' Open directly from SharePoint open in the Desktop application and not the browser?
Once the workbook is opened in the browser (Edge in that case), VBA stops working!!!
Thanks in advance...
GiGi
When you grab a “copy link” from Teams/SharePoint, that’s a sharing link meant to open in the browser (Excel Online). VBA can’t run there.
If you want to open the file directly in Excel Desktop via VBA, you need to use the native SharePoint/OneDrive path instead of the web “sharing link”.
Sharing link:
Looks like https://tenant.sharepoint.com/:x:/r/sites/...
→ opens in browser, no VBA.
Direct SharePoint/OneDrive path:
Looks like https://tenant.sharepoint.com/sites/TeamName/Shared Documents/General/Test.xlsx
→ opens in Excel Desktop when used with Workbooks.Open
Or, if you have the OneDrive sync client running, you can use the local sync path like:
C:\Users\<you>\OneDrive - Contoso\TeamName\General\Test.xlsx
That way, Excel opens the real file in Desktop and your VBA works normally.
Example VBA: Open in Desktop and Save Copy.
Sub SaveFromSharePoint()
Dim wb As Workbook
Dim localPath As String
Dim spPath As String
' Local path for saving a copy
localPath = Environ("USERPROFILE") & "\Downloads\Test.xlsx"
' Use the full direct SharePoint document library URL
spPath = "https://contoso.sharepoint.com/sites/TeamName/Shared Documents/General/Test.xlsx"
' Open in Desktop Excel
Set wb = Workbooks.Open(spPath)
' Save a copy locally
wb.SaveCopyAs localPath
wb.Close SaveChanges:=False
MsgBox "Saved to: " & localPath, vbInformation
End Sub
To get the direct URL:
Go to the document library in SharePoint (not just Teams chat → Files).
Right-click the file → Details → Copy the full path from the properties pane.
(It should end in .xlsx and not have ?web=1 at the end).
Hope this will help you.