I am using VBA in Excel and I am trying to access a webpage and then click on a link to trigger a CSV download on my PC.
With VBA I am able so far to open IE and access the required Webpage. But after inspecting the HTML code of the page (F12) and using getElementsByClassName and other methods I cannot product a clickable object that will trigger the download from my code.
Sub Automate_IE_Enter_Data() 'This will load a webpage in IE Dim i As Long Dim URL As String Dim IE As Object Dim objElement As Object Dim objCollection As Object Dim HWNDSrc As Long
'Create InternetExplorer Object
Set IE = CreateObject("InternetExplorer.Application")
'Set IE.Visible = True to make IE visible, or False for IE to run in the background
IE.Visible = True
'Define URL
'URL = "https://www.automateexcel.com/excel/vba"
URL = "https://www.barchart.com/futures/quotes/ZWF9|530P/price-history/historical"
'Navigate to URL
IE.Navigate URL
' Statusbar let's user know website is loading
Application.StatusBar = URL & " is loading. Please wait..."
' Wait while IE loading...
'IE ReadyState = 4 signifies the webpage has loaded (the first loop is set to avoid inadvertantly skipping over the second loop)
'Do While IE.ReadyState = 4: DoEvents: Loop
Do Until IE.ReadyState = 4: DoEvents: Loop
'Webpage Loaded
Application.StatusBar = URL & " Loaded"
'Get Window ID for IE so we can set it as activate window
HWNDSrc = IE.hWnd
'Set IE as Active Window
SetForegroundWindow HWNDSrc
Set IEAppColl = IE.Document.getElementsByClassName("bc-glyph-download")(0)
IEAppColl.Click
Application.Wait Now + TimeValue("00:00:10")
SetForegroundWindow HWNDSrc
Application.Wait Now + TimeValue("00:00:05")
End Sub
Expected: 1) Open on IE the following URL: https://www.barchart.com/futures/quotes/ZWF9|530P/price-history/historical 2) Click the "max" link on the Daily Prices section to download a CSV file
1) is OK 2) produces the error: Object does not support this property or method.
I am not click as to how to replicat the clicking of the "max" link in my VBA Code. Not sure I am using ist correct name.