Dim bot As New WebDriver, rng As RangeĢ.set range to list of cells in column A Set rng = Range(Worksheets("keywords").Range("A2"), Worksheets("keywords").Range("A2").End(xlDown))Ībove code makes setting a range dynamic because of End(xlDown)Įnd(xlDown) = next non empty cell in that row (the cell you reach when you press ctrl + down in excel)ģ.Start web driver bot.Start "chrome", ""Ĥ.Loop through each cell in range, search keyword in google For Each cell In rngīot.FindElementByName("q").SendKeys (cell.Value)īot.TakeScreenshot.SaveAs (ActiveWorkbook.Path + "/screenshot_" + cell.Value + ".jpg") Lets start by adding a sub Public Sub keywordsearch()ġ.Define WebDriver and a Range to get range of keywords. List of keywords are in column A of keywords sheet. Lets say I’m an SEO analyst, I want to search few words on google and take screenshot of results. I’ll be explaining few practical situations of automation later in this tutorial. Too easy right! But who wants a screenshot of google? Ah yes, this simple example is used just to explain the steps in automation. 'quit method for closing browser instance.Ībove code is self explanatory, when you run this code a screenshot of website is saved in the folder in which current excel file is present. open website using Get method and screenshot using TakeScreenshot method Public Sub seleniumtutorial()īot.TakeScreenshot.SaveAs (ActiveWorkbook.Path + "/screenshot.jpg") This can be done in just 2 lines of code. Lets say we have to open a website and take screenshot of it. Syntax : driver.Start "browsername", "baseurl"Ĭurrently supports chrome, firefox, opera, PhantomJS & IE bot.Start "chrome", "" Simple example This driver is used to start and automate the browser.Ī browser can be started by using start method of webdriver. Syntax : Dim drivername as new WebDriver Dim bot as new WebDriver Selenium web driver is what controls the browser. Go to tools > references > check ‘Selenium Type Library’ and click ok.
Selenium VBA wrapper library – you can download and install it from hereġ.Open any excel file, go to code editor (Alt + f11) and create a sub.
most of them use Internet explorer by adding a reference to Microsoft Internet controls. When it comes to browser automation tasks in Excel VBA like filling a web form, login to a website etc.