I'm using VBA to navigate IE and am having trouble resetting the document object so that I can navigate through multiple pages. I used the answer to this question to help create the original script, but am running in to a very similar problem that poster ran in to. Unfortunately, the answer listed does not help or guide me to a solution.
I'm using the following code to pull the page and navigate.
Sub UpdatesalesNotes()
Dim ie As Object, ieDoc As HTMLDocument
Set ie = CreateObject("InternetExplorer.Application")
ie.Visible = True
strHTML = ActiveSheet.Range("A31").Value
ie.navigate strHTML
'wait for browser
While ie.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
Set ieDoc = ie.Document
Call ClickButton(ieDoc, "New Service Note")
'wait for browser
While ie.ReadyState <> READYSTATE_COMPLETE
DoEvents
Wend
ieDoc.getElementById("00Nj0000009FpF9").Value = "Placeholder Text"
Call ClickButton(ieDoc, "Save")
End Sub
The element I'm interacting with on the second page is a text box. The function called (which works fine) is listed below.
Function ClickButton(ieDoc As HTMLDocument, ByVal strButtonName As String)
Dim objInputs As Object, ele As Variant
Set objInputs = ieDoc.getElementsByTagName("input")
For Each ele In objInputs
If ele.Title = strButtonName Then
ele.Click
End If
Next
End Function
How do I reset ieDoc to equal the current page so that I am able to interact with the text box on the new page? Inserting the following before interacting with the text box does not work (and I have no idea why).
set ieDoc = ie.document
Thank you very much for any help you're able to offer!