views:

214

answers:

2

I'm am trying to write vba code to fill out web-forms and click buttons for me. I am looping through the various option tags on the page to select the one I want. When I reach it, I want to select it, but I'm not sure of the syntax.

Dim htmlO As HTMLOptionElement
For Each htmlO In Object.getElementByTagName("option")
    If Trim(htmlO.value) = "INS" Then
       htmlO.????  (click? select?)
        Exit For
    End If
Next

Here is the HTML from the webpage:

<select gtbfieldid="40" id="menu" name="pv_choice">
<option selected="selected" value="ZZZ">Choose Menu Option
</option><option value="BL_COMP">Blanket Companies
</option><option value="CARR_SEARCH">Carrier Search
</option><option value="PASSWORD">Change Password
</option><option value="FED_REG">FMCSA Register
</option><option value="FEEDBACK">Feedback
</option><option value="HOME">Home Page
</option><option value="INS">Insurance Filing
</option><option value="OOS_LIST">Out Of Service Carriers
</option></select>

I want to select the option "INS".

+1  A: 

I haven't used VBA so I apologize in advance but assuming it uses the same structure for the DOM than other languages I'm familiar with, try:

htmlO.selected= "selected"

which is how I would achieve this in javascript :)

HTH

Gazillion
Thank you for your answer...but it doesn't work. The menu option does not get selected when I do htmlO.check.
dmr
Sorry, I'm a doofus, I thought you were working with check boxes. Try selected="selected"Updated in my original response.
Gazillion
I tried htmlO.select also and it didn't work...thanks though :)
dmr
Are you sure you tried "selected" and not "select"?
Gazillion
A: 

What worked in the end was...

Dim htmlO As HTMLSelectElement
Set htmlS = objdoc.getElementById("menu")
htmlS.selectedIndex = 7

I had to reference the entire menu and choose which one to select, not select the individual option.

dmr