12. VbScript | Internet Explorer: Sendkeys Automation

Remember to try the code on your own so that you retain what you learn. Ask if something doesn’t make sense!

So this tutorial will be about automating VbScript using Internet Explorer. Internet Explorer is special compared to other browsers because Internet Explorer is built into Windows, and can be called by the CreateObject function. This may not be the same for other browsers, since they aren’t a part of windows default programs.

Calling Internet Explorer

So the first step would be to call the Internet Explorer application using CreateObject. You can the store this action as the ie variable. You can then tell the Internet Explorer Application to Navigate to google. And in order to make the application visible on your display you set the the visible function to 1 or true. Setting the visible function to 0 or false makes the application not appear on your display; essentially making it run in the “background”.


The Internet Explorer opens to Google.com


Miscellaneous Points

if you want to get ride of the cluttering of the Internet Explorer window, you can set the toolbar to 0 and the status bar to 0 to remove them from the window. Like so:


The Toolbar and Status bars are no longer showing in the Internet Explorer window.

Internet Explorer window without the tool or status bar


Other Options:

The height & width controls the size of the Internet Explorer window by the number of pixels. So height=560 means the height of the window is 560 pixels. The Top & Left controls where the window is placed on the desktop. So if Top & Left are both set to 0, then the window’s upper left hand corner perfectly fits the Top-Left part of your display. Resizable controls whether the window can be resized to a different height & width manually by the user’s mouse. Resizable at 0 means that user cannot change the dimensions of the window.

Time for Automation!


So users usually use google to search for a key term. This key term they type via keyboard. So to mimic the actions of a user’s keyboard input, we are going to use sendkeys.


The script opens an Internet Explorer browser that navigates to google.com, inputs the search term “cow”, and inputs the ENTER key to complete the google search.


But what if you are using a website like Facebook? You replace the google url with www.facebook.com and plan out what a user normally hits on a keyboard to log into facebook.

Note that for some websites like Facebook, it may have a longer loading time, such that the sendkeys don’t have enough time to input the keyboard strokes after the page has loaded, such that the login fields aren’t filled. To tell the vbscript to wait until the the facebook page loads, we use the wscript.sleep command to tell it to wait a # of milliseconds. An alternative to wscript.sleep is to use something called the busy command with a wait loop. The busy command simply checks if the application is busy, which in this case is the Internet Explorer application. You then setup a loop to wait a set amount of time until the Internet Explorer application is no longer busy. The script would look something like this:

Random Notes:

  • Information needed to replace wscript.sleep with readyState=4 [link]

One thought to “12. VbScript | Internet Explorer: Sendkeys Automation”

  1. Instead of wscript.sleep use readystate = 4 (Page is fully loaded – 4)

    Do Until ie.readyState = 4

What's Your Opinion?