VBA to fill web forms

AldoP

New Member
Joined
Sep 16, 2015
Messages
2
Hello guys,

I’m trying to fill a web form for filling multiple boxes trough vba, the website works this way...

You input a ticket number, the website redirects you to the main HUB and from there you gotta fill 40 boxes, but the problem is that every time that I enter a new ticket number the Name box and ID box changes..

Is there a way to use the VBA code to use the tabindex and not the name or id box ?

Take a look on my code and give me your thoughts on this, it will be highly appreciated,

Sub FillIE()


Dim ie As New InternetExplorer
Dim LookUpAddress As String
Dim LookUpCity As String
Dim LookUpZip As String
Dim HtmlDoc As HTMLDocument
Dim WS As Worksheet

Set WS = ActiveSheet


'Load webpage and loop until loading is complete.
ie.Navigate " Insert Website in here"
Do Until ie.ReadyState = READYSTATE_COMPLETE
Loop
Set HtmlDoc = ie.document
With ie
.Visible = True
.AddressBar = True
.Toolbar = True
End With

LookUpAddress = WS.Cells(1, 2)
LookUpCity = WS.Cells(2, 2)
LookUpZip = WS.Cells(3, 2)

'problem is here I want to assign the tabindex of the HTML code

HtmlDoc.forms("addressLookupForm").address.Value = LookUpAddress
HtmlDoc.forms("addressLookupForm").city.Value = LookUpCity
HtmlDoc.forms("addressLookupForm").zipCode.Value = LookUpZip


'Close ie object
Set ie = Nothing

End Sub


Regards,
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
The other code that i been using is the following...


Sub FillInternetForm()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")


IE.navigate "https://www.change.org/p/justice-for-cecil-the-iconic-collared-lion-slaughtered-by-trophy-hunter"


IE.Visible = True
While IE.Busy
DoEvents
Wend
IE.document.all("first_name").Value = ThisWorkbook.Sheets("sheet1").Range("a1")
IE.document.all("last_name").Value = ThisWorkbook.Sheets("sheet1").Range("a2")
IE.document.all("email").Value = ThisWorkbook.Sheets("sheet1").Range("a3")

IE.document.all("address").Value = ThisWorkbook.Sheets("sheet1").Range("a5")
IE.document.all("postal_code").Value = ThisWorkbook.Sheets("sheet1").Range("a6")
IE.document.all("message").Value = ThisWorkbook.Sheets("sheet1").Range("a7")
End Sub


This works like a charm if the Name of the box is the same...
 
Upvote 0

Forum statistics

Threads
1,215,219
Messages
6,123,687
Members
449,117
Latest member
Aaagu

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top