VBA code to Enter Data to Webpage or IE

VBA Enter Data into webpage – IE Automation using VBA GetElementByID function

What is it:

If you are trying to do ie automation or trying to enter data to webpage using VBA then this post if for you. We will show the step by step instructions on how to enter/fill data in ie using VBA.

enter data to webpage

Why is it:

This is very helpful when you want to enter or fill multiple fields in a webpage regularly. Or if you want to login to website in a single click without using the browser’s default Remember My Password option etc.

How to enter data to webpage using vba

In this example we are using Excel VBA for IE Automation however you can use any VBA supported platform.

Step 1: Open the Excel workbook and got to VBA code builder (Alt + F11) and Open a New Module.

enter data to webpage

Step 2: Copy and Paste the below code in it.

Private Sub wpieautologin()

Dim ie As SHDocVw.InternetExplorer

Set ie = New SHDocVw.InternetExplorer

ie.Visible = True 

ie.Navigate “http://www.askeygeek.com/wp-admin” ‘we are trying to login to askeygeek.com admin page



Loop Until ie.readystate = 4

‘ie READYSTATE has 5 different status codes, here we are using status 4:

‘Uninitialized = 0

‘Loading = 1

‘Loaded = 2

‘Interactive =3

‘Complete = 4 

Call ie.Document.GetElementByID(“user_login”).SetAttribute(“value”, “testUser”)

Call ie.Document.GetElementByID(“user_pass”).SetAttribute(“value”, “testPass12345”)

 ‘to find the “<input……/>” tag hyper link and to click the button

Set AllInputs = ie.Document.getelementsbytagname(“input”) ‘you can use any tagname as you wish

    For Each hyper_link In AllInputs

        If hyper_link.Name = “wp-submit” Then ‘you can use .name, .id etc


            Exit For

        End If




Loop Until ie.readystate = 3



Loop Until ie.readystate = 4

End Sub

Step 3: Click the Run button or F5.(Also you can insert a button/shape in excel sheet then right click and assign this macro to run every time.)

enter data to webpage

Notes 1: Make sure ‘Microsoft Internet Controls’ is enabled from the Tools – References.

IE Automation


Notes 2: Right click the webpage to and click View source to find the GetElement values



About Anson

I’m Anson having a decade of versatile experience in Business Process Outsourcing, Finance & Accounting, Information Technology, Operational Excellence & Business Intelligence. I have got the opportunity to work for Genpact, Hewlett Packard, M*Modal and Capgemini in various roles and responsibilities, starting from an Associate to a Manager. Learning anything new has always been my passion and if related to Business and Technology then I love it. asKeygeek.com is an outcome of my passion towards the same and I have been into asKeygeek since 2012. Outside business and technology I’m a movie buff who spends hours together watching and learning Cinema, I do make Short Films 🙂


  1. Hi,

    I have to click on a additional message from web page, can you help me with the code. I’m struck at the this final part of clicking ok on it

  2. Can you help me here?
    There is no id or value set in the following lines of code, how do I insert say into the “lastnameFilter” or “firstnameFilter”?

    Learner’s ID

    First Name

    Family Name



  3. I am getting error at Call ie.Document.GetElementByID(“user_login”).SetAttribute(“value”, “testUser”)

    Error: Run-time error 424: object required.

    Can you please help me.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.