I'm trying to use Excel VBA to navigate to a webpage, fill in a form, and click a button. Right now the code I'm using loads the webpage and fills in the webpage form fine. But the code I'm using to try and click the ("Lookup") button gives me a Run-time error '424': Object Required.
Any help would be so appreciated.
Here's the code I'm using:
Sub WebForm()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate "https://lambda.byu.edu/ae/prod/person/cgi/personLookup.cgi"
IE.Visible = True
While IE.Busy Or IE.readyState <> 4
DoEvents
Wend
IE.document.all("inpSearchPattern").Value = "Some Last Name"
IE.document.all("doNewLookup(document.personxref)").Click
End Sub
CodePudding user response:
Try this one, it worked for me.
Sub WebForm()
Dim IE As Object
Set IE = CreateObject("InternetExplorer.Application")
IE.navigate "https://lambda.byu.edu/ae/prod/person/cgi/personLookup.cgi"
IE.Visible = True
While IE.Busy Or IE.readyState <> 4
DoEvents
Wend
IE.Document.all("inpSearchPattern").Value = "J*n"
Set objCollection = IE.Document.getElementsByTagName("input")
i = 0
While i < objCollection.Length
'MsgBox "i= " & i & " Name " & objCollection(I).Name & _
" Value " & objCollection(I).Value & _
" Type " & objCollection(I).Type
If (objCollection(i).Value = "Lookup" And objCollection(i).Type = "button") Then
Set objElement = objCollection(i)
End If
i = i 1
Wend
objElement.Click ' click button to load the form
End Sub