Display a SharePoint Site
I have to admit that I wrote my own VBA procedure to do this at one point—but I didn’t need to. The Workbook object’s FollowHyperlink
method provides a built-in way to display the SharePoint site or any web page using the default browser.
How to do it
The SharedWorkspace object provides a URL
property that returns the address of the shared workspace. You can use this property or the SPSITE constant with the FollowHyperlink
method to display the site:
ThisWorkbook.FollowHyperlink ThisWorkbook.SharedWorkspace.URL
Or:
ThisWorkbook.FollowHyperlink SPSITE
If you’re going to perform an action on the current workbook, you may need to close the workbook as part of the process and display the SharePoint site. For example, you can’t check a workbook back in from its own code. The following code warns the user that she can’t check an open file in, and then it displays the SharePoint site:
Dim sw As SharedWorkspace, msg As String
Set sw = ThisWorkbook.SharedWorkspace
' Can't check ThisWorkbook in! Must close first.
If sw.Connected Then
msg = "You must close this workbook before it can be checked in. " & _
"OK to close? After closing you can check in from SharePoint."
If MsgBox(msg, vbYesNo) = vbYes Then
ThisWorkbook.Save
ThisWorkbook.FollowHyperlink sw.URL
ThisWorkbook.Close
End If
End IfHow it works
Because Excel doesn’t wait for FollowHyperlink to finish, the preceding code works smoothly, saving and closing the workbook while the SharePoint site displays. ...