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
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
property that returns the address of the shared workspace. You can use this property or the SPSITE constant with the
method to display the site:
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 If
How it works
Because Excel doesnât wait for
FollowHyperlink to finish, the preceding code works smoothly, saving and closing the workbook while the SharePoint ...