First web scraping project!
I've been copying various web scraping code from here but can't get around a
run time error 13: Type Mismatch
on the .document.getElementById("")
line I'm using to set a variable for a hyperlink I want to click. I figured it should be treated like the log-in button that I successfully coded. I'm not sure if I am missing a library I should be using, as pretty much every other post had different issues and solutions than what I'm running into. What am I doing wrong here?
I'm using IE11 and Excel 2010. I started adding libraries I thought might provide a solution. The libraries I've activated are as follows:
- Visual Basic For Applications
- Microsoft Excel 14.0 Object Library
- OLE Automation
- Microsoft Office 14.0 Object Library
- Microsoft HTML Object Library
- Microsoft Internet Controls
- Microsoft XML, v6.0
- Microsoft Shell Controls And Automation
Here is the code and HTML DOM snippet:
Sub IEScrape()
'we define the essential variables
Dim ie As Object
Dim pwd, username
Dim button
Dim MemAss
'add the "Microsoft Internet Controls" reference in your VBA Project indirectly
Set ie = New InternetExplorerMedium
With ie
.Visible = True
.navigate ("internalwebsite.com")
While ie.readyState <> 4
DoEvents
Wend
Set username = .document.getElementById("userid") 'id of the username control (HTML Control)
Set pwd = .document.getElementById("password") 'id of the password control (HTML Control)
Set button = .document.getElementById("loginbtn") 'id of the button control (HTML Control)
username.Value = "username"
pwd.Value = "password"
button.Click
While ie.readyState <> 4
DoEvents
Wend
'Run time error 13: Type mismatch on next line!!!
Set MemAss = .document.getElementById("Menu:membershipassociation") 'id of the link (HTML Control)
MemAss.Click
While ie.readyState <> 4
DoEvents
Wend
End With
Set ie = Nothing
End Sub