Excel VBA: Open Hyperlink in Chrome (3 Examples)

This article illustrates how to open a hyperlink in the Google Chrome browser using VBA code in Excel. We’ll use the Shell function to define the browser path and hyperlink address to accomplish this. Let’s dive into the examples to learn how to open hyperlinks in Chrome in Excel VBA.


Excel VBA: Open Hyperlink in Chrome: 3 Examples

The Shell function is used to run an executable program using its file location from inside a VBA code. This function takes two arguments

Shell(pathname, [windowstyle])

Here, we need to correctly configure the pathname of the hyperlink to open it in the Chrome browser. The pathname argument consists of two parts– the 1st part holds the file location of Chrome’s executable program in the computer’s local storage and the 2nd part is for setting the hyperlink to open.

To get the file location of Chrome’s executable file, navigate to Drive C>>Program Files (x86)>>Google>>Chrome>>Application. This is the default file location for google Chrome to install on windows.

Excel VBA Open Hyperlink in Chrome

For the 2nd part, we can set the hyperlink hardcoded in the VBA code or get it as a cell value from the Excel worksheet.

Write Code in Visual Basic Editor

To open hyperlinks in the Chrome browser, we need to open and write VBA code in the visual basic editor. Follow the steps to open the visual basic editor and write some code there.

  • Go to the Developer tab from the Excel Ribbon.
  • Click the Visual Basic option.

  • In the Visual Basic for Applications window, click the Insert dropdown to select the New Module

Now put your code inside the visual code editor and press F5 to run it.


1. Open a Specific Hyperlink in Chrome with Excel VBA

Task: In this example, we’ll open a hyperlink that is hardcoded in the VBA code in the Google Chrome browser. The following VBA code will open the Exceldemy website in a new tab in Chrome.

Code: Let’s copy and paste the VBA code into the visual basic editor and press F5 to run it.

Sub OpenHyperlinkInChrome()
 Dim chromeFileLocation As String
  Dim hyperlink As String
  hyperlink = "https://www.exceldemy.com/"
  chromeFileLocation = """C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"""
  Shell (chromeFileLocation & "-url " & hyperlink)
End Sub

Excel VBA Open Hyperlink in Chrome

Code Explanation:
In the above code, we defined two variables named chromeFIleLoaction and hyperlink as a string. We set Chrome’s executable file location in the first variable enclosed by two double quotations. Click on the address bar in the windows explorer to get the file location.

Excel VBA Open Hyperlink in Chrome

On the other hand, the 2nd variable holds the hyperlink (https://www.exceldemy.com/) of the Exceldemy website.

Then finally we combined these two variables to define the pathname argument of the Shell function in our VBA code.


2. Open a Hyperlink in Chrome Using Cell Reference in Excel VBA Code

Task: Let’s say we have a URL in cell B4 in the active worksheet. We want to run a VBA code that’ll extract the hyperlink from the cell reference and then open it in a Chrome window.

Excel VBA Open Hyperlink in Chrome

Solution: We have to use the Range.Hyperlinks property of Excel to get the hyperlink of the defined cell reference. Then we’ll use the Hyperlinks.Item property to get the address as a string.

Code: Let’s copy and paste the VBA code into the visual basic editor and press F5 to run it.

Sub OpenHyperlinkInChrome()
Dim chromeFileLocation As String
Dim hyperlink As String
hyperlink = ActiveSheet.Range("B4").Hyperlinks.Item(1).Address
chromeFileLocation = """C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe"""
Shell (chromeFileLocation & "-url " & hyperlink)
End Sub

Read More: VBA to Add Hyperlink to Cell Value in Excel


3. Run a VBA Code to Open Hyperlink in Chrome Based on Selection

Task: We have a list of URLs in cells B5:B11. We want to open these URLs in the same Chrome window but in different tabs based on user selection. In the following screenshot, we’ve shown the list with the extracted hyperlinks in the next column.

Excel VBA Open Hyperlink in Chrome

Solution: In our code, we’ll use the Application.Selection property to get the cell references that hold the selected URLs in the current worksheet. To loop through the multiple selections, we need to use the For each…Next statement in our VBA code.

Code: Here, we’ve selected 3 different cells (B5, B6, B8) from the list.

Excel VBA Open Hyperlink in Chrome

Let’s copy and paste the VBA code into the visual basic editor and press F5 to run it.

Sub OpenHyperlinksInChrome()
    Dim chromeFileLocation, hyperlink As String
    Dim Rng, SelectRange As Range
chromeFileLocation = """C:\Program Files (x86)\Google\Chrome\Application\Chrome.exe"""
On Error Resume Next
Set SelectRange = Application.Selection
For Each Rng In SelectRange
    hyperlink = Rng.Hyperlinks.Item(1).Address
    Shell (chromeFileLocation & "-url " & hyperlink)
Next
End Sub

Notes

As usual, when we hit on a hyperlink from the Excel sheet, it opens the link in the computer’s default browser. We can easily check and reset the default browser if necessary. To do that, search for the “Default web browser” in the start menu.

Then choose to reset the default browser from the available list.


Download Practice Workbook


Conclusion

Now, we know how to open hyperlinks in Google Chrome with examples.  Hopefully, it would help you to use the functionality more confidently. Any questions or suggestions don’t forget to put them in the comment box below.


Related Articles

Get FREE Advanced Excel Exercises with Solutions!
Al Arafat Siddique
Al Arafat Siddique

Al Arafat Siddique, BSc, Naval Architecture and Marine Engineering, Bangladesh University of Engineering and Technology, has worked on the ExcelDemy project for two years. He has written over 85+ articles for ExcelDemy. Currently, he is working as a software developer. He is leading a team of six members to develop Microsoft Office Add-ins, extending Office applications to interact with office documents. Other assigned projects to his team include creating AI-based products and online conversion tools using the latest... Read Full Bio

4 Comments
  1. Thank you very much! I’ll try. If can I ask something, is possible scrap in a chrome browser with this?

  2. Hello

    I followed your instructions but often get a 404 error. As you can see from the code I am looking for books using ISBN number. Sometimes it works, sometimes not (more often fail than success).

    I have tried all sorts of checks on the ISBN number and can manually get there by typing in an ISBN that has previously failed.

    I am bamboozled.

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    Dim lngRow As Long
    Dim strChromeLocation As String
    Dim strISBN As String
    Dim lngISBN As Single
    Dim strURL As String

    lngRow = Target.Row
    strISBN = Cells(lngRow, 8)
    strURL = “https://www.isbnsearcher.com/books/” & strISBN
    strChromeLocation = “””C:\Program Files (x86)\Google\Chrome\Application\chrome.exe”””

    Shell (strChromeLocation & “-url ” & strURL)

    End Sub

    • Hello JEFF WHALE,

      Thank you very much for following our articles.

      You mentioned that your sample code is not working properly. We attached a VBA code that will help you to solve this problem. You need to choose a cell from the dataset that contains an ISBN number when running the code. One thing adding that change the location of Chrome according to your computer.

      And you are getting this 404 error because without any ISBN number, this isbnsearcher.com/books link will show an error by default.

      Sub OpenstrHyperlinkInChrome()
      Dim strChromeLocation As String
      Dim strURL As String
      Dim strISBN As String
      strISBN = Application.InputBox("Please Select Desired Cell", Type:=8)
      strURL = "https://www.isbnsearcher.com/books/" & strISBN
      strChromeLocation = """C:\Program Files\Google\Chrome\Application\chrome.exe"""
      Shell (strChromeLocation & "-url " & strURL)
      End Sub

Leave a reply

Advanced Excel Exercises with Solutions PDF

 

 

ExcelDemy
Logo