Selenium – How to update ChromeDriver using VBA

The macro below updates the local ChromeDriver to the most recent version using VBA:

    Sub DownloadChromeDriver()
        Dim url As String
        Dim fileName As String
        Dim req As Object
        Dim stream As Object
        
        ' Set the URL and file name for the latest ChromeDriver
        url = "https://chromedriver.storage.googleapis.com/LATEST_RELEASE"
        fileName = "chromedriver.zip"
        
        ' Make an HTTP request to get the latest ChromeDriver version number
        Set req = CreateObject("MSXML2.XMLHTTP")
        req.Open "GET", url, False
        req.Send
        
        ' Get the latest ChromeDriver version number from the response
        Dim latestVersion As String
        latestVersion = req.responseText
        
        ' Construct the URL for the ChromeDriver binary based on the version number
        url = "https://chromedriver.storage.googleapis.com/" & latestVersion & "/chromedriver_win32.zip"
        
        ' Make an HTTP request to download the ChromeDriver binary
        req.Open "GET", url, False
        req.Send
        
        ' Save the downloaded binary to disk
        Set stream = CreateObject("ADODB.Stream")
        stream.Type = 1 ' Binary
        stream.Open
        stream.Write req.responseBody
        stream.SaveToFile fileName, 2 ' Overwrite existing file
        stream.Close
        
        ' Extract the downloaded binary to a known location on your computer
        Dim zipFilePath As String
        zipFilePath = ActiveWorkbook.Path & "\" & fileName
        Dim extractPath As String
        extractPath = Environ("userprofile") & "\AppData\Local\SeleniumBasic"
        
        Set objShell = CreateObject("Shell.Application")
        Set objSource = objShell.NameSpace(zipFilePath).Items()
        Set objTarget = objShell.NameSpace(extractPath)
        
        objTarget.CopyHere objSource, 16
        
        
        MsgBox "ChromeDriver version " & latestVersion & " installed successfully."
    End Sub

The video below breaks it down: