VBA code to enter data into a web page.

IMEXCELING

New Member
Joined
Jul 18, 2015
Messages
7
Hi Gang.

Need support with a macro to populate a webpage. I'm new to VBA and can't seem to figure out how to solve this.


When complete, the macro should:

Open internet explorer
go to a specific web page
enter in a postal code
click on the next page
wait 10 seconds to load
enter in a year
enter in a vehicle make
enter in a vehicle model

etc.


The problem i'm having is that the "vehicle make" has a dropdown "list box selections: that affect the "vehicle model" and I can't get vba to correctly enter in the vehicle make. VBA will enter in the "Make" but the list box for the model won't appear.

I need VBA to enter in all the fields automatically and I need to figure out how VBA can correctly enter in the vehicle make and the webpage allows vba to enter in the model.

Here is the code:

Code:
Dim HTMLDoc As HTMLDocument
 Dim MyBrowser As InternetExplorer
  Sub Kanetix()

  Dim MyHTML_Element As IHTMLElement
  Dim MyURL As String
  On Error GoTo Err_Clear
  MyURL = "https://www.kanetix.ca"
  Set MyBrowser = New InternetExplorer
  MyBrowser.Silent = True
  MyBrowser.navigate MyURL
  MyBrowser.Visible = True
  Do
  Loop Until MyBrowser.readyState = READYSTATE_COMPLETE
  Set HTMLDoc = MyBrowser.document
  HTMLDoc.all.POSTAL_CODE.Value = "l9a 2z3" 'places in postal code
  For Each MyHTML_Element In HTMLDoc.getElementsByTagName("input")
  If MyHTML_Element.Type = "submit" Then MyHTML_Element.Click: Exit For
  Next 'goes to the next page
Err_Clear:
  If Err <> 0 Then
  Err.Clear
  Resume Next
  End If

Do
DoEvents
Loop Until ie.readyState = 4
    
    
Application.Wait (Now + TimeValue("0:00:10")) 'wait till page loads

HTMLDoc.all.VehicleYear_1.Value = "2014"
HTMLDoc.all.VehicleMake_1.selectedIndex = "3"
HTMLDoc.all.VehicleModel_1.selectedIndex = "3"
HTMLDoc.all.Vehicle_purchase_month_1.Value = "November"
Application.Wait (Now + TimeValue("0:00:06"))
HTMLDoc.all.Leased_1.Value = "no"
HTMLDoc.all.Vehicle_purchase_year_1.Value = "2014"


MsgBox "done"

End Sub



I am using 2013.

I am open to suggestions

Thank you
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)

Forum statistics

Threads
1,215,446
Messages
6,124,904
Members
449,194
Latest member
JayEggleton

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