Search code examples
excelvbaseleniumautomation

Automation Error when running Selenium VBA on Excel 2019


I was running the following code without a problem on a machine with excel 2013. We recently upgraded to Excel 2019 and the macro now returns an Automation error. I noticed that the error seems to be in the driver.start section , it looks like it's not 'registering' the reference. I have reinstalled the Selenium add-in , re-pointed the reference, tried different browsers ( chrome, edge etc) but to no avail .

Dim driver As New WebDriver
Dim keyObj As Selenium.keys
Dim IE As Object

Set keyObj = New Selenium.keys

driver.Start "ie"
driver.Window.Maximize
driver.Get "https://www.google.com/"

Any suggestions/ ideas would be much appreciated.


Solution

  • enter image description hereTry adding Selenium to references (Selenium Type Library).

    It solved the error for me.

    When you installed Selenium you checked the drivers? enter image description here

    If you are using Chrome, have you downloaded the same version of chrome driver as your chrome browser version?

    First of all, go to control panel and uninstall previous installation of selenium and then follow the steps 1- Download the latest version of chrome and make sure of the version of Chrome from Help >> About Google Chrome. You would see something like that Version 75.0.3770.142 (Official Build) (32-bit)

    2- Download the latest version from the LINK

    3- Download the chromedriver from the follwoing LINK Make sure of the version that suits your chrome version As for the Google Chrome version I posted the most suitable version of chromedriver is ChromeDriver 75.0.3770.140

    Now setup SeleniumBasic >> After setup unzip the chromedriver file chromedriver_win32.zip and copy the chromedriver.exe to the path of selenium Here's two possibilties: First >> C:\Program Files\SeleniumBasic Second >> C:\Users%username%\AppData\Local\SeleniumBasic Copy the chromedriver.exe to the SeleniumBasic path

    Open new blank excel file >> Press Alt + F11 (Visual Basic Editor) >> Tools >> References >> Selenium Type Library

    Insert new module and paste the following code to test

    Sub Test()
        Dim sel As New WebDriver
        
        sel.Start "chrome", "https://www.google.com"
        sel.Get "/"
        Stop
    End Sub