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 versatile experience in Business Process Outsourcing, Finance & Accounting, Information Technology, Operational Excellence & Business Intelligence. I'm currently working in a MNC in Bangalore, India. Learning anything new has always been my passions and if its related to Business and Technology then, I love it. This website/blog is an outcome of my passion towards it and I have been blogging since 2012. Outside business and technology I’m a movie freak who spends hours together watching and learning Cinema.


  1. 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