Excel VBA FollowHyperlink Method

This Excel VBA tutorial explains how to use VBA FollowHyperlink Method to open website.

VBA FollowHyperlink Method

FollowHyperlink is used to tell Excel to open up a browser and go to a specific website, or download a file in specific folder, depending on your “Hyperlink” address.

In Excel spreadsheet, there is a similar worksheet function called Hyperlink, but it converts a text to hyperlink but FollowHyperlink function actually “go to” hyperlink.

Syntax of FollowHyperlink Method

expression .FollowHyperlink(Address, [SubAddress], [NewWindow], [AddHistory], [ExtraInfo], [Method], [HeaderInfo])
Address Required String. The address of the target document.
SubAddress Optional Variant. The location within the target document. The default value is the empty string.
NewWindow Optional Variant. True to display the target application in a new window. The default value is False.
AddHistory Optional Variant. Not used. Reserved for future use.
ExtraInfo Optional Variant. A String or byte array that specifies additional information for HTTP to use to resolve the hyperlink. For example, you can use ExtraInfo to specify the coordinates of an image map, the contents of a form, or a FAT file name.
HeaderInfo Optional Variant. A String that specifies header information for the HTTP request. The defaut value is an empty string.

Example 1

The below example opens a browser and go to website. As the Sub procedure runs, browser will open.

Public Sub openBrowser()
ActiveWorkbook.FollowHyperlink ("http://yahoo.com")
End Sub

Example 2

The below example downloads and opens the file in cache. As you click on the “save” button,  you will be asked to save the file in a new location, because you are not opening the actual file in the path.

Public Sub openCache()
ActiveWorkbook.FollowHyperlink ("C:\setup.log")
End Sub

Example 3 – open website in specific browser

If you encounter web addresses that are opened in Excel browser instead of IE, you can explicitly tell Excel to open in specific browser such as open in Firefox, just find the path of the exe of the browser.

excel vba followhyperlink 01



Public Sub specific_browswer()
    sPath = "C:\Program Files\Internet Explorer\iexplore.exe"
    'OR sPath = "C:\Users\wywong\AppData\Local\Mozilla Firefox\firefox.exe"
    sURL = "http://yahoo.com.hk"
    dummy = Shell(sPath & " " & sURL, vbNormalFocus)
End Sub


Outbound References




Leave a Reply

Your email address will not be published.