chemebabak
Technical User
So I want to use Excel VBA to open and manipulate websites. I have selected Microsoft HTML Object Library and Microsoft Internet Controls in VBA references. I want to select a radio button from a group using excel VBA. I keep getting a Run-time error '13': Type mismatch. on the radio button variable:
I have tried dimming the different MSHTML classes for radio button, including "Dim TempUnits As Object". They all give a type mismatch. What am I doing wrong?
Code:
' Dim TempUnits As HTMLButtonElement
' Dim TempUnits As HTMLElementCollection
' Dim TempUnits As HTMLInputButtonElement
' Dim TempUnits As HTMLInputElement
' Dim TempUnits As HTMLOption
' Dim TempUnits As HTMLOptionButtonElement
Dim TempUnits As HTMLOptionElement
Set TempUnits = webbookForm("TUnit")
TempUnits.Value = "F"
Code:
Sub NIST_webbook()
'
Const cURL = "[URL unfurl="true"]http://webbook.nist.gov/chemistry/fluid/"[/URL] 'Enter the web address here'
Dim IE As InternetExplorer
Set IE = New InternetExplorer
IE.Visible = True
IE.Navigate cURL
'Wait for initial page to load
Do While IE.ReadyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
Dim doc As HTMLDocument
Set doc = IE.Document
'Get the only form on the page
Dim webbookForm As HTMLFormElement
Set webbookForm = doc.forms(0)
Dim ChemSpeciesDropdownBox As HTMLDListElement
Set ChemSpeciesDropdownBox = webbookForm("ID")
ChemSpeciesDropdownBox.Value = "C106978"
Dim TempUnits As HTMLButtonElement
Set TempUnits = webbookForm("TUnit")
TempUnits.Value = "F"
' NextButton.Click
' '
' '
' 'Wait for the new page to load
'
' Do While IE.ReadyState <> READYSTATE_COMPLETE Or IE.Busy: DoEvents: Loop
End Sub