0

I'm attempting to fill out a web form based on some VBA code I pulled from the interwebz - but when VBA fills in the text fields and I click submit - it does not recognize the text fields as completed - showing "Required*"

The web form i'm trying to fill out is https://www.retailmenot.com/everyday/unsubscribe I'm fairly new at this so any help is appreciated!

Sub RetailMeNot()
'RetailMeNot.com


Dim HTMLDoc As HTMLDocument
Dim oBrowser As InternetExplorer
Dim oHTML_Element As IHTMLElement
Dim sURL As String
Dim Name, Address, Apt, City, State, Zip, Email As String

Name = "Test"
Address = "123 Apple St"
Apt = ""
City = "New York"
State = "NY"
Zip = "123456"
Email = "Test@VBA.com"


'On Error GoTo Err_Clear
sURL = "https://www.retailmenot.com/everyday/unsubscribe"
Set oBrowser = New InternetExplorer
oBrowser.Silent = True
'oBrowser.timeout = 60
oBrowser.navigate sURL
oBrowser.Visible = True

Do
' Wait till the Browser is loaded
Loop Until oBrowser.readyState = READYSTATE_COMPLETE

Set HTMLDoc = oBrowser.document

HTMLDoc.getElementsByClassName("nameinputfield")(0).Value = Name
HTMLDoc.getElementsByClassName("address2inputfield").Item(0).Value = Address
HTMLDoc.getElementsByClassName("aptnuminputfield").Item(0).Value = Apt
HTMLDoc.getElementsByClassName("cityinputfield").Item(0).Value = City
HTMLDoc.getElementsByClassName("stateinputfield").Item(0).Value = State
HTMLDoc.getElementsByClassName("zipinputfield").Item(0).Value = Zip
HTMLDoc.getElementsByClassName("emailinputfield").Item(0).Value = Email
HTMLDoc.getElementsByClassName("input-checkbox").Item(0).Checked = True
HTMLDoc.getElementsByClassName("button-primary").Item(0).Click

Exit Sub


Err_Clear:
If Err <> 0 Then
Debug.Assert Err = 0
Err.Clear
Resume Next
End If
End Sub
eli
  • 1
  • Sometimes you have to enter the field and exit it for the input checking to run. So select each field before you fill the data. – HackSlash Dec 22 '20 at 21:28
  • The text fields have onChange events you must trigger. The checkbox has a click event. Look here how you can find events (screenshots under the code) and how to work with (code) https://stackoverflow.com/questions/63294113/automate-ie-via-excel-to-fill-in-a-dropdown-and-continue/63299608#63299608 – Zwenn Dec 27 '20 at 11:47

0 Answers0