20

I'm trying to open a Chrome browser from VBA. I understand Chrome does not support ActiveX settings so I'm curious if theres any work-arounds?

Dim ie As Object 
Set ie = CreateObject("ChromeTab.ChromeFrame")
ie.Navigate "google.ca" 
ie.Visible = True
1
  • Can Chrome be the standard browser, or do you need to open Chrome even if it's not? If it's the first case I guess you could use something like ShellExecute and the URL.
    – Bart
    May 6, 2011 at 18:20

6 Answers 6

28
shell("C:\Users\USERNAME\AppData\Local\Google\Chrome\Application\Chrome.exe -url http:google.ca")
5
  • 2
    Hi @ray, What if it is a dynamic website. i tried Shell (chromePath & " -url " & websiteaddress). But it failed to load the page but only load the main page of google.
    – useR
    Jan 27, 2015 at 8:36
  • 1
    Can you interact with the application? If i wanted to do some analysis on the returned HTML for example?
    – SimaPro
    Nov 3, 2016 at 19:17
  • 3
    I'm sure you meant this - but the user needs to find out who the current user is before this code will work. You can do that using: current_user = (Environ$("Username")) then doing ChromePath = """c:\users\" & current_user & "\AppData\Local\Google\Chrome\Application\Chrome.exe""" Feb 21, 2017 at 15:30
  • @useR I know its late but I am searching the same and find out Shell ("C:\Users\DELL\AppData\Local\Google\Chrome\Application\Chrome.exe -url " & URL) work for me (there is a space after -url )
    – VBAbyMBA
    Feb 18, 2019 at 6:59
  • To add to this answer, my application was found here: C:\Program Files (x86)\Google\Chrome\Application\chrome.exe. To find it, I right clicked on the application icon and clicked on "Properties". That told me where the shortcut icon pointed to. I hope this helps anyone else that is looking for where their Chrome.exe is being housed. Sep 23, 2019 at 23:42
11

Worked here too:

Sub test544()

  Dim chromePath As String

  chromePath = """C:\Program Files\Google\Chrome\Application\chrome.exe"""

  Shell (chromePath & " -url http:google.ca")

End Sub
1
  • Hi @ahmad, What if it is a dynamic website. i tried Shell (chromePath & " -url " & websiteaddress). But it failed to load the page but only load the main page of google.
    – useR
    Jan 27, 2015 at 8:35
7

I found an easier way to do it and it works perfectly even if you don't know the path where the chrome is located.

First of all, you have to paste this code in the top of the module.

Option Explicit
Private pWebAddress As String
Public Declare Function ShellExecute Lib "shell32.dll" Alias "ShellExecuteA" _
(ByVal hwnd As Long, ByVal lpOperation As String, ByVal lpFile As String, _
ByVal lpParameters As String, ByVal lpDirectory As String, ByVal nShowCmd As Long) As Long

After that you have to create this two modules:

Sub LoadExplorer()
    LoadFile "Chrome.exe" ' Here you are executing the chrome. exe
End Sub

Sub LoadFile(FileName As String)
    ShellExecute 0, "Open", FileName, "http://test.123", "", 1 ' You can change the URL.
End Sub

With this you will be able (if you want) to set a variable for the url or just leave it like hardcode.

Ps: It works perfectly for others browsers just changing "Chrome.exe" to opera, bing, etc.

4

You can use the following vba code and input them into standard module in excel. A list of websites can be entered and should be entered like this on cell A1 in Excel - www.stackoverflow.com

ActiveSheet.Cells(1,2).Value merely takes the number of website links that you have on cell B1 in Excel and will loop the code again and again based on number of website links you have placed on the sheet. Therefore Chrome will open up a new tab for each website link.

I hope this helps with the dynamic website you have got.

Sub multiplechrome()

    Dim WebUrl As String
    Dim i As Integer

    For i = 1 To ActiveSheet.Cells(1, 2).Value
        WebUrl = "http://" & Cells(i, 1).Value & """"
        Shell ("C:\Program Files (x86)\Google\Chrome\Application\chrome.exe -url " & WebUrl)

    Next
End Sub
3

The answer given by @ray above works perfectly, but make sure you are using the right path to open up the file. If you right click on your icon and click properties, you should see where the actual path is, just copy past that and it should work.

Properties

1

You could use selenium basic to launch and interact with Chrome. After installation you will need to add a reference to Selenium Type library.

Option Explicit
Public Sub Demo()
    Dim d As WebDriver
    Set d = New ChromeDriver
    Const URL = "https://www.google.com/"

    With d
        .Start "Chrome"
        .get URL
        .FindElementById("lst-ib").SendKeys "Selenium basic GitHub"
         .FindElementsByTag("form")(1).FindElementByCss("input[value='Google Search']").Click
        '.Quit
    End With
End Sub

Not the answer you're looking for? Browse other questions tagged or ask your own question.