Trying to click a link in IE using VBA

Bak92

New Member
Joined
Oct 31, 2022
Messages
1
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Hi All,
I am trying to work on a Macro to login into a website and then download some data. Currently I am having trouble getting it to click on a link in the site.

Code:
VBA Code:
Sub GetHTLMDocuments()

    Dim IE As New SHDocVw.InternetExplorerMedium
    Dim HTMLDoc As MSHTML.HTMLDocument
    Dim HTMLInput As MSHTML.IHTMLElement
    Dim HTMLButtons As MSHTML.IHTMLElementCollection
    Dim HTMLButton As MSHTML.IHTMLElement

    IE.Visible = True
    IE.navigate "xxx.yyy"

    Do While IE.readyState <> READYSTATE_COMPLETE
        Application.Wait Now + TimeValue("00:00:03")
        DoEvents
    Loop
    
    Application.Wait Now + TimeValue("00:00:02")
    
    ShowWindow IE.hwnd, SW_MAXIMIZE

    Set HTMLDoc = IE.document
    
    Application.Wait Now + TimeValue("00:00:02")
    
    Set ElementCol = IE.document.getElementById("periods")
      For Each btnInput In ElementCol
          If btnInput.Value = "selected" Then
              btnInput.Click
              Exit For
          End If
      Next btnInput

    IE.Quit

End Sub

Here's the html code from the site:

CaptureIe.PNG


I would like to change the class which state the selected (or unselected) of the "option" element, any idea?
 

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.

Forum statistics

Threads
1,224,815
Messages
6,181,136
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