Tom’s Tutorials For Excel: Hyperlinking a CommandButton to the Internet
When you have an ActiveX CommandButton on a UserForm or embedded onto your worksheet, the FollowHyperlink
method can take you to your favorite website.
In the above picture, the green CommandButton’s caption is the literal URL address. This Click
event procedure in the worksheet’s module reads that caption and takes you to that website.
Private Sub CommandButton1_Click()
ActiveWorkbook.FollowHyperlink _
Address:=CommandButton1.Caption
End Sub
In the next picture, the salmon-colored CommandButton has a more user-friendly caption. The code associated with it is an example of placing the literal URL in the Click
event procedure.
This is the procedure for the salmon-colored button.
Private Sub CommandButton1_Click()
ActiveWorkbook.FollowHyperlink _
Address:="http://www.atlaspm.com"
End Sub
Recall that to place the code into the worksheet module, you can either double-click the CommandButton while in Design mode, or simply right-click the worksheet tab, left-click to select View Code, and paste either of the above procedures into the large white pane that is the worksheet module. From there, press Alt+Q
to return to the worksheet.
Below are pictures to show the code’s implementation process, and the resulting image of, in this example, your favorite website (this one!).
Clicking the CommandButtons as pictured above takes you here!
Leave a Reply