VBA to Select Campus Name from Multiselect Dropdown List on Web Page

bmacias

Board Regular
Joined
Sep 11, 2002
Messages
217
Hi,

I'm having trouble selecting one of the options from a dropdown list, you have the ability to select several options at the same time.

the element is :

<select name="ctl00$plc$RegionDistrictCampus1$campusList" onchange="javascript:setTimeout('__doPostBack(\'ctl00$plc$RegionDistrictCampus1$campusList\',\'\')', 0)" id="plc_RegionDistrictCampus1_campusList" style="height:20px;width:255px;">


I have tried:

With IE.document.getElementById("plc_RegionDistrictCampus1_campusList")
.Options(0).Selected = True '1st option
.Options(3).Selected = True '3rd option
'etc.
End With

But I'm getting an Object Required error. How can I do it to select the 3rd option?


screeenshot.png
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Is the select element available/ready? Maybe this:
VBA Code:
    Dim selectElement As Object
    Do
        Set selectElement = IE.document.getElementById("plc_RegionDistrictCampus1_campusList")
        DoEvents
    Loop While selectElement Is Nothing
    selectElement.Options(0).Selected = True '1st option
    selectElement.Options(3).Selected = True '3rd option
 
Upvote 0
Is the select element available/ready? Maybe this:
VBA Code:
    Dim selectElement As Object
    Do
        Set selectElement = IE.document.getElementById("plc_RegionDistrictCampus1_campusList")
        DoEvents
    Loop While selectElement Is Nothing
    selectElement.Options(0).Selected = True '1st option
    selectElement.Options(3).Selected = True '3rd option
Unfortunately, it still didn't work. I'm still getting an "Object Required" error. HOWEVER, could it be that I'm attempting to control the wrong item/ID and this is one is the one I should program to? Which I still don't know how to do it, but I see that the names of the campuses I want to check are there...

<div id="ctl00_plc_RegionDistrictCampus1_multiCampusList_DropDown" class="RadComboBoxDropDown RadComboBoxDropDown_Default " style="width: 253px; display: block; top: 0px; visibility: visible; transition: none 0s ease 0s;"><div class="rcbScroll rcbWidth" style="height: 110px;"><ul class="rcbList"><li class="rcbItem"><label><input type="checkbox" class="rcbCheckBox">FALFURRIAS ELEM</label></li><li class="rcbItem"><label><input type="checkbox" class="rcbCheckBox">FALFURRIAS H S</label></li><li class="rcbItem"><label><input type="checkbox" class="rcbCheckBox">FALFURRIAS INNOVATION ACADEMY</label></li><li class="rcbHovered" aria-checked="true"><label><input type="checkbox" class="rcbCheckBox">FALFURRIAS J H</label></li><li class="rcbItem"><label><input type="checkbox" class="rcbCheckBox">LASATER EL</label></li></ul></div></div>

So for my example I want to select the elementary and Junior High campuses, FALFURRIAS ELEM & FALFURRIAS J H respectively
 
Upvote 0
So it's a simulated dropdown then, not a real select element. Maybe this:
VBA Code:
    Dim div As Object
    Set div = IE.document.getElementById("ctl00_plc_RegionDistrictCampus1_multiCampusList_DropDown")
    div.GetElementsByTagName("INPUT")(0).Checked = True  '1st checkbox
    div.GetElementsByTagName("INPUT")(3).Checked = True  '4th checkbox
 
Upvote 0
Solution
So it's a simulated dropdown then, not a real select element. Maybe this:
VBA Code:
    Dim div As Object
    Set div = IE.document.getElementById("ctl00_plc_RegionDistrictCampus1_multiCampusList_DropDown")
    div.GetElementsByTagName("INPUT")(0).Checked = True  '1st checkbox
    div.GetElementsByTagName("INPUT")(3).Checked = True  '4th checkbox

Thats it! Thank you so much for your assistance and my apologies for taking so long to respond.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

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