FollowHyperlink()

Open a Document or Web Page Using Excel Visual Basic

The general format is:

FollowHyperlink(Document_Address, Location_Address, New_Window, History, Information, Method, Header)
Parameter Description
Document_Address REQUIRED. The location of the document or URL of the web page
Location_Address OPTIONAL. An area within the document to navigate to.
New_Window OPTIONAL. Boolean indicator (True or False) to tell the method whether you want a new window to open up or not. *My experience – True or False, it doesn’t seem to change how it behaves; most of the time I just set it to True just in case.
History OPTIONAL. This does nothing. *Last I knew this didn’t do anything; I have no idea what it is for. According to Microsoft, the official parameter name is “AddHistory.”
Information OPTIONAL. Provide additional information regarding coordinates within the target document.
Method OPTIONAL. A numerical constant value (0 or 1) for resolving the information parameter to “Get” or “Post” functionality. Is the information parameter appended to the Document_Address (Get) or is it posted as a byte array (Post)?

 

Constant Numeric Value
msoMethodGet 0
msoMethodPost 1
Header OPTIONAL. Header information for an HTTP request.

 

Example 1:

Private Sub CommandButton1_Click()
     Call ActiveWorkbook.FollowHyperlink("https://google.com")
 End Sub
Private Sub CommandButton1_Click()
     Call ActiveWorkbook.FollowHyperlink("https://google.com", NewWindow:=False)
 End Sub
Private Sub CommandButton1_Click()
     Call ActiveWorkbook.FollowHyperlink("https://google.com", NewWindow:=True)
 End Sub

All three code samples above open up Google in a new tab using your default web browser.

 

Example 2:

Private Sub CommandButton1_Click()
     Call ActiveWorkbook.FollowHyperlink("C:\Users\Cerberus\Desktop\mercurial.png")
 End Sub

The above code opens up a file contained on my Dekstop.

 

Example 3:

Private Sub CommandButton1_Click()
     Call ActiveWorkbook.FollowHyperlink("C:\Users\Cerberus\Desktop\BalanceTracker.xlsx", "B226")
 End Sub

This code uses the Location_Address parameter. It opens up an Excel document on my Desktop, navigates to Cell B226, and activates that cell making it the active cell.

 

Example 4:

Private Sub CommandButton1_Click()
     Call ActiveWorkbook.FollowHyperlink("C:\Users\Cerberus\Desktop\BalanceTracker.xlsx", "A100:B226")
 End Sub

This code uses the Location_Address parameter. It opens up an Excel file on my Desktop and navigates to Cell A100. It activates the entire range of cells from A100 to B226.

 

Excel VBA Resources

 

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.