HTML combobox

Eriasu

New Member
Joined
Jan 17, 2021
Messages
6
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi everyone!

I am fairly new to VBA and HTML magic, I use the following code to choose from a combobox:

Option Explicit
Const sWebPage = "https://analytics.emea.teleperformance.com/ibmcognos/bi/"

Sub IEBot()

Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible = True

IE.navigate sWebPage

While IE.ReadyState <> 4
DoEvents
Wend

Dim oHDoc As HTMLDocument
Set oHDoc = IE.document

Dim oHEle As HTMLSelectElement
Set oHEle = oHDoc.getElementById("main")
oHEle.selectedIndex = "1

End Sub


I get the Run-time error '438':
Object doesn't support this property or method.

Any help will be much appreciated!
 

Attachments

  • HTML snip.JPG
    HTML snip.JPG
    103.7 KB · Views: 14
  • References.JPG
    References.JPG
    38.3 KB · Views: 13

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
The dropdown doesn't have an ID but it has a name - CAMNameSpace, so instead of GetElementById try GetElementsByName.
 
Upvote 0
The dropdown doesn't have an ID but it has a name - CAMNameSpace, so instead of GetElementById try GetElementsByName.

Hi Norie, thanks for the tip!

I switched to

Set oHEle = oHDoc.getElementsByName("CAMNameSpace")

but now get the Run-time error '13': Type mismatch

Any workaround in mind?
 
Upvote 0
Set oHEle = oHDoc.getElementsByName("CAMNameSpace")(0)

Cheers, I now receive the Run-time error '91':

Object variable or With block variable not set; oHEle.selectedIndex ="1" is yellow highlighted.
 
Upvote 0
The name is CAMNamespace, so try:
VBA Code:
Set oHEle = oHDoc.getElementsByName("CAMNamespace")(0)
oHEle.selectedIndex = 1
 
Upvote 0
The name is CAMNamespace, so try:
VBA Code:
Set oHEle = oHDoc.getElementsByName("CAMNamespace")(0)
oHEle.selectedIndex = 1

Cheers John; was a typo, apologies.

Same error occurs though.
 
Upvote 0
It could be a timing issue, meaning the element isn't available when the getElementsByName is executed. To confirm this, click Debug on the error message and drag the yellow execution arrow up to the getElementsByName line and press F5 to continue execution from that line.

If that works change the code so that it waits until the element is available:
VBA Code:
    Do
        Set oHEle = oHDoc.getElementsByName("CAMNamespace")(0)
        DoEvents
    Loop While oHEle Is Nothing
    oHEle.selectedIndex = 1
 
Upvote 0
Solution
It could be a timing issue, meaning the element isn't available when the getElementsByName is executed. To confirm this, click Debug on the error message and drag the yellow execution arrow up to the getElementsByName line and press F5 to continue execution from that line.

If that works change the code so that it waits until the element is available:
VBA Code:
    Do
        Set oHEle = oHDoc.getElementsByName("CAMNamespace")(0)
        DoEvents
    Loop While oHEle Is Nothing
    oHEle.selectedIndex = 1

It was a timing issue afterall ty!!!! Works now
 
Upvote 0

Forum statistics

Threads
1,214,591
Messages
6,120,426
Members
448,961
Latest member
nzskater

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