vba changing the selection in a html dropdown menu within a form

jlecl033

New Member
Joined
Feb 7, 2011
Messages
13
hello all,

I am trying to change the selection in a html dropdown menu within a form with vba in order to collect information on the next page.

here is what I have at the moment.
Code:
With appIE

    ' change page
    .Document.forms("portfolioView").getElementsByTagName("pv_id") = "2"
    
.Quit
End With
portfolioView is the name of the form and pv_id is the name of the dropdown menu. Here is the html code that concerns my situation.

HTML:
<select name="pv_id" size="1" onchange="submit()">


<option value="5">ENERGY STAR Recognition</option>

<option value="19">Performance: Data Centers</option>
<option value="4">Performance: Environmental</option>

<option value="3">Performance: Financial</option>

<option value="14">Performance: GHG Emissions</option>

<option value="8">Performance: Rating/Improvement</option>

<option value="12">Performance: Targets</option>

<option value="9">Performance: Water Use</option>
<option value="17">Performance: Water/Wastewater Treatment Facilities</option>

<option value="2">Summary: Energy Use</option>

<option value="1" selected="selected">Summary: Facilities</option>

</select></td>

Thanks for your help
 

Some videos you may like

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,604
.Document.forms("portfolioView").getElementsByTagName("pv_id") = "2"

But pv_id isn't a HTML tag name; the tag name is the select tag. Try this:
Code:
With appIE
    .document.forms("portfolioView").getElementsByTagName("select")("pv_id").Value = "2"
    Do While .Busy Or .readyState <> READYSTATE_COMPLETE: DoEvents: Loop
End With
 

jlecl033

New Member
Joined
Feb 7, 2011
Messages
13
[SOLVED] vba changing the selection in a html dropdown menu within a form

That seems to work. I also found that this works as well.

Code:
With appIE
    ' change page
    .Document.forms("portfolioView").Item("pv_id").Value = "2"
    ' loop until the page finishes loading
    Do While .Busy Or .ReadyState <> READYSTATE_COMPLETE
    DoEvents
    Loop
end with
 

jlecl033

New Member
Joined
Feb 7, 2011
Messages
13
hi,

Something very strange is happening now. In my previous message, I mentionned that I had found a way to change the selection in a dropdown menu within a form with vba (see previous in threads).

Now, when I choose the new selection, I thought it would change the page automatically but it isn't. Why would it not change and is there a way to go around this?

thanks to John_W who has helped me thus far.

Thank you
 

jlecl033

New Member
Joined
Feb 7, 2011
Messages
13
actually, reading solution from another forum, I found the fireEvent tool.

for the forum's sake, this is the final code concerning this thread.

Code:
With appIE
    ' change page
    .Document.forms("portfolioView").Item("pv_id").Value = "2"
    .Document.forms("portfolioView").Item("pv_id").FireEvent ("onChange")
   ' loop until the page finishes loading
    Do While .Busy Or .ReadyState <> READYSTATE_COMPLETE
    DoEvents
    Loop
end with
 

shalini_murali

New Member
Joined
Apr 3, 2014
Messages
1
Hi all,

I am trying to change the selection from a dropdown menu within a form in <ACRONYM title="visual basic for applications">vba</ACRONYM>.

Here is the code that i have worked out as per above example but it didnt work:

With IE
.document.forms("frmWFtoolbar").Item("selwpActions").Value = "E-mail document"
.document.forms("frmWFtoolbar").Item("selwpActions").fireevent ("onChange")
Do While .Busy Or .ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
End With

Here is the html code that concerns my situation:

<td align="center">
<form name="frmWFtoolbar" action="">
<label for="selwpActions"></< font>label><select id="selwpActions" name="selwpActions" size="1" onChange="doSelected
(this.options[this.selectedIndex].value)" class="formAttribute">
<option value="">------------------ Select ----------------</</< font>option>
<option value="Open"> Open</< font color="#0000ff" <>option>
<option value="Email">E-mail document</< font color="#0000ff" <>option>
</< font>select>
</< font>form>
</< font>td>


Can anyone help me on, selecting the option "E-mail document"?
 
Last edited:

Watch MrExcel Video

Forum statistics

Threads
1,122,303
Messages
5,595,324
Members
413,986
Latest member
Elizsk

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
Top