Search code examples
htmlexcelie-automationvba

VBA IE Automation: Get URL from within element


I am trying to get the URL from inside the second element in the "pShowMore" class.

I have this:

For Each wd In CreateObject("Shell.Application").Windows
    If InStr(wd.LocationName, "Institution") <> 0 Then
        Exit For
    End If
Next wd

Dim newURL As String

newURL = wd.document.getElementsByClassName("pShowMore").getElementsByTagName("a")(1).getAttribute("href")

And I get the error: 438-"Object doesn't support the property or method" for the retrieval (i.e., wd.document.....)

What can I do to get the URL in the href? Also, why does it not support the property or method?


Solution

  • It turns out I was just getting an error cycling through the open windows.

    I used

        On Error Resume Next
    

    This solved the specific problem I was having.