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: 10
  • References.JPG
    References.JPG
    38.3 KB · Views: 10

Some videos you may like

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,270
Office Version
  1. 365
Platform
  1. Windows
The dropdown doesn't have an ID but it has a name - CAMNameSpace, so instead of GetElementById try GetElementsByName.
 

Eriasu

New Member
Joined
Jan 17, 2021
Messages
6
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
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?
 

Eriasu

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

ADVERTISEMENT

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.
 

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,712
The name is CAMNamespace, so try:
VBA Code:
Set oHEle = oHDoc.getElementsByName("CAMNamespace")(0)
oHEle.selectedIndex = 1
 

Eriasu

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

ADVERTISEMENT

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.
 

John_w

MrExcel MVP
Joined
Oct 15, 2007
Messages
6,712
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
 
Solution

Eriasu

New Member
Joined
Jan 17, 2021
Messages
6
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
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
 

Watch MrExcel Video

Forum statistics

Threads
1,127,370
Messages
5,624,294
Members
416,018
Latest member
mirceaon

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