VBa and IE dropdown Menu

30136353

Board Regular
Joined
Aug 14, 2019
Messages
105
HI Guys,

Been having a lot of success lately with automating IE tasks using VBA. HOWEVER, I have one drop down menu I just cannot get the code right to select my item.

I can successfully identify the drop down and click on it, but cannot select an option. I have tried selectedindex, value =, I also altered the inner text with a FireEvent Onchange but it would not recognise it. I also used send keys to manually navigate the drop down but this failed when I introduced a loop later...

VBA Code:
Sub Toggle()

    Dim I As Long
Dim href As String
Dim URL As String
Dim URL2 As String
Dim IE As Object
Dim objElement As Object
Dim objCollection As Object
Dim HWNDSrc As Long
Dim htmlSelect

Set IE = GetObject("new:{D5E8041D-920F-45e9-B8FB-B1DEB82C6E5E}")
URL = "http://taddsmigui.nat.bt.com/TADDSGUI/#"
URL2 = "http://taddsmigui.nat.bt.com/HHTGUI/"

IE.Visible = True

I = 2

Do While Not IsEmpty(Worksheets("Test Data").Cells(I, 7).Value)

IE.Navigate URL2

Sleep 2000

    IE.document.getElementsByClassName("ui-selectmenu-text")(1).Click

VBA Code:
<select name="periodNumDaysBefore" id="periodNumDaysBefore" style="width: 128%; display: none;">
                  <option value="0">Today Only</option>
                  <option value="1">Last 2 Days</option>
                  <option value="7">Last Week</option>
                  <option value="14">Last Fortnight</option>
                  <option value="30">Last Month</option>
                  <option value="60">Last 2 Months</option>
                  <option value="90">Last 3 Months</option>
                  <option value="-1">User Defined Range</option>
                  <option value="Base">Baseline</option>
                </select>
<span tabindex="0" class="ui-selectmenu-button ui-widget ui-state-default ui-corner-all" id="periodNumDaysBefore-button" role="combobox" aria-disabled="false" aria-expanded="false" aria-haspopup="true" aria-labelledby="ui-id-1" aria-activedescendant="ui-id-1" aria-owns="periodNumDaysBefore-menu" style="width: 243px;" aria-autocomplete="list"><span class="ui-icon ui-icon-triangle-1-s"></span><span class="ui-selectmenu-text">Today Only</span></span>
<span class="ui-icon ui-icon-triangle-1-s"></span>
<span class="ui-selectmenu-text">Today Only</span>
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Your VBA code is incomplete, but looking at the code, you appear to be clicking on the HTML element with the class name "ui-selectmenu-text". Looking at the HTML code, this appears to be the SPAN element:

<span class="ui-selectmenu-text">Today Only</span>

So essentially all you're doing is clicking on text. What happens when you click on the dropdown box in IE? Does it do anything, or is there another button you need to press before anything happens?
 
Upvote 0

Forum statistics

Threads
1,214,979
Messages
6,122,551
Members
449,088
Latest member
davidcom

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