Web automation using Internet Explorer

Do You want to have the same automation in web as in your Excel or SAP? In todays article I’m going to show You how to create web automation using good old buddy Internet Explorer.

Internet Explorer was on the top of browsers…

…almost 20years ago. Currently it is not supported since 2015…

Now You probably ask – why can’t we use any other browser than Internet Explorer? Good question, but the answer is simple. Internet Explorer is a Microsoft company product, so every Windows user has got it on his PC – at least for now. Additionally You can already find the library in the VBE References, so there will be no problem to begin the work with that.

References

If You want to start with the early binding, You’ll need 2 references. Set in the options – Microsoft Internet Controls for the InternetExplorer object and Microsoft HTML Object Library for HTMLDocument object.

Of course You can go with the late binding. Setting everything as Object variable is good, but it is easier to begin with early binding.

Variables

The main 2 variables in our code are InternetExplorer object for the application and HTMLDocument for the website.

Dim IE As InternetExplorer
Dim doc As HTMLDocument

The third one, which is also needed at least is the string for the URL.

Dim URL As String

As the example website I took this site.

Web automation

So having set the application and the URL

Set IE = New InternetExplorer
Let URL = "https://www.simpleexcelvba.com/"

we can set the visibility of the application to see what is happening and go to specified URL in the IE object.

IE.Visible = True
IE.navigate URL

To wait until the page loads we can use here the most common method in the Internet.

Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop

Thanks to that the code will not go further until everything is loaded on site.

One last thing before scraping the website is to set the site – HTML document – to the variable.

Set doc = IE.Document

Scrape the website data

For the purpose of this article we will do the basic thing – use the site’s browser. To start scraping first of all right click on the specified website and choose Inspect.

After that You will see additional window, something like VBE Immediate & Watch window mixed together.

This console window is showing us the code, which is responsible for how website is shown.

Get those site elements

Now choose the Select element to inspect icon in the upper left corner of the console.

Then click on the SimpleExcelVBA browser on the main page.

Thanks to that the console will highlight the code line, which stands to showing the browser.

The best to use will be the name of this element – s.

doc.getElementsByName("s").Item(0).Value = "Connect to SAP"

To do the actual automate search we need to click magnifier icon next to the browser. Inspect this element same as I described that in browser case and the console will highlight the line.

In this situation we will use class as identifier.

doc.getElementsByClassName("search-submit").Item(0).Click

Worth to remember

If the .Value property, .Click method or anything is not working try with that trick of .Item(0) like I did here!

Full search automation code

Getting all together we achieve just a simple example of how to do automated search on SimpleExcelVBA.

Option Explicit

 Sub automateIE()

 Dim IE As InternetExplorer
 Dim doc As HTMLDocument
 Dim URL As String

 Set IE = New InternetExplorer

 Let URL = "https://www.simpleexcelvba.com/"

 IE.Visible = True
 IE.navigate URL

 Do While IE.readyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop

 Set doc = IE.Document
 doc.getElementsByName("s").Item(0).Value = "Connect to SAP"
 doc.getElementsByClassName("search-submit").Item(0).Click

 End Sub

I hope that from now on, using this example, You will be able to start web automation using Internet Explorer!

Author: Tomasz Płociński

I'm very advanced in VBA, Excel, also easily linking VBA with other Office applications (e.g. PowerPoint) and external applications (e.g. SAP). I take part also in RPA processes (WebQuery, DataCache, IBM Access Client Solutions) where I can also use my SQL basic skillset. I'm trying now to widen my knowledge into TypeScript/JavaScript direction.

5 thoughts on “Web automation using Internet Explorer”

  1. Thanks for this amazing video, you know if a new library will be available for Microsoft edge?

    1. Hello Ivan,
      I’m not sure IF the new library for Microsoft Edge will come out.
      If You are interested in Edge automation, try the Selenium Basic.
      It can automate Chrome, Firefox and also Edge.

  2. Thankyou i am new to it and learning , i was trying to make a simple thing to click a button on apage but was unable to do so .because of some dumb errors and this page helped me after 2 days of searching and getting irrritated 😀

Leave a Reply

Your email address will not be published. Required fields are marked *