Skip to content

Instantly share code, notes, and snippets.

@erajanraja24
Created July 31, 2016 17:26
Show Gist options
  • Save erajanraja24/a6b1704233c8af0b5398835dd4b21af1 to your computer and use it in GitHub Desktop.
Save erajanraja24/a6b1704233c8af0b5398835dd4b21af1 to your computer and use it in GitHub Desktop.
Automate Internet Explorer with Excel VBA Part 3
Sub automaticformfilling()
Dim ie As Object
Set ie = CreateObject("internetexplorer.application")
With ie
.Visible = True
.navigate "http://newtours.demoaut.com/mercuryregister.php"
'Wait for loading
Do While .busy
DoEvents
Loop
Do While .readystate <> 4
DoEvents
Loop
End With
Set fname = ie.document.getelementbyid("firstName")
fname.Value = "First Name"
Set lastName = ie.document.getelementbyid("lastName")
lastName.Value = "Last Name"
Set phone = ie.document.getelementbyid("phone")
phone.Value = "54646346"
Set UserName = ie.document.getelementbyid("userName")
UserName.Value = "[email protected]"
Set address1 = ie.document.getelementbyid("address1")
address1.Value = "Add 1"
Set address2 = ie.document.getelementbyid("address2")
address2.Value = "Add 2"
Set city = ie.document.getelementbyid("city")
city.Value = "Tim"
Set State = ie.document.getelementbyid("state")
State.Value = "Iowa"
Set postalCode = ie.document.getelementbyid("postalCode")
postalCode.Value = "45345"
Set country = ie.document.getelementbyid("country")
For i = 1 To country.Options.Length
If country.Options(i).Text = "INDIA" Then
country.selectedindex = i
Exit For
End If
Next i
Set Email = ie.document.getelementbyid("email")
Email.Value = "[email protected]"
Set Password = ie.document.getelementbyid("password")
Password.Value = "pwd@123"
Set confirmPassword = ie.document.getelementbyid("confirmPassword")
confirmPassword.Value = "pwd@123"
ie.document.forms(0).submit
End Sub
@LeonardodaV
Copy link

@ODaddy63
Maybe it can help you.

Sub automaticformfilling()

    Dim ie As InternetExplorer
    Dim doc As HTMLDocument

Set ie = CreateObject("internetexplorer.application")

With ie
    .Visible = True
    .navigate "http://newtours.demoaut.com/mercuryregister.php"
    'Wait for loading
Do While .Busy
    DoEvents
Loop

Do While .readyState <> 4
    DoEvents
Loop

End With
Set doc = ie.document
Set fname = doc.getElementById("firstName")
fname.Value = "First Name"


Set lastName = doc.getElementById("lastName")
lastName.Value = "Last Name"


Set phone = doc.getElementById("phone")
phone.Value = "54646346"


Set UserName = doc.getElementById("userName")
UserName.Value = "[email protected]"


Set address1 = doc.getElementById("address1")
address1.Value = "Add 1"


Set address2 = doc.getElementById("address2")
address2.Value = "Add 2"


Set city = doc.getElementById("city")
city.Value = "Tim"


Set State = doc.getElementById("state")
State.Value = "Iowa"


Set postalCode = doc.getElementById("postalCode")
postalCode.Value = "45345"


Set country = doc.getElementById("country")

For i = 1 To country.Options.Length
    If country.Options(i).Text = "INDIA" Then
        country.selectedIndex = i
        Exit For
    End If
Next i

Set Email = doc.getElementById("email")
Email.Value = "[email protected]"


Set Password = doc.getElementById("password")
Password.Value = "pwd@123"

Set confirmPassword = doc.getElementById("confirmPassword")
confirmPassword.Value = "pwd@123"

doc.forms(0).submit
End Sub

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment