VBa and IE dropdown Menu

30136353

Board Regular
Joined
Aug 14, 2019
Messages
88
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>
 

Some videos you may like

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Dan_W

Active Member
Joined
Jul 11, 2018
Messages
258
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?
 

Watch MrExcel Video

Forum statistics

Threads
1,118,890
Messages
5,574,853
Members
412,623
Latest member
princexxa
Top