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

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Dan_W

Well-known Member
Joined
Jul 11, 2018
Messages
1,087
Office Version
  1. 365
Platform
  1. Windows
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?
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,167,960
Messages
5,856,525
Members
431,820
Latest member
Tori Murphy

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