VBA Enter Data into webpage – IE Automation using VBA GetElementByID function
Che cosa è:
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.
Pin
Perché è:
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.
Come 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.
Sottomarino privato wpieautologin()
Fioco ie COME SHDocVw.InternetExplorer
Set ie = Nuovo SHDocVw.InternetExplorer
ie.Visible = VERO
ie.Navigate “https://www.askeygeek.com/wp-admin” ‘we are trying to login to askeygeek.com admin page
Do
DoEvents
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
Per Each hyper_link In AllInputs
Se hyper_link.Name = “wp-submit” Allora ‘you can use .name, .id etc
hyper_link.Click
Exit Per
End Se
Prossimo
Do
DoEvents
Loop Until ie.readystate = 3
Do
DoEvents
Loop Until ie.readystate = 4
End Sub
Notes 1: Make sure ‘Microsoft Internet Controls’ is enabled from the Tools – References.
Notes 2: Right click the webpage to and click View source to find the GetElement values
7 risposte
Can You make this same work for my Edge Browser
hi team, i need to fill the data in Browser tab, which is already opened and navigated to the exact page, where i need to fill my data, please provide the VBA code to deal with this session.
CIAO,
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
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
Nome di battesimo
Family Name
Search
Grazie
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.
oh i fixed myself. Typo error. Thanks
Still I am getting the same error