LewisHoulden
New member
- Local time
- Today, 18:03
- Joined
- Jul 16, 2013
- Messages
- 4
My first post! I have used this forum many times to help solve VBA queries but cannot seem to find an answer to my query: :banghead:
Ok, so I can currently open a new internet explorer instance, navigate to my URL, then use the .getElementByID to insert my preference into a textbox on the page. Looks like this:
Now, that works fine. I want to take this a step further and use an existing internet explorer window. I can find the already existing IE window, open a new tab to same URL as previous, but I am stopped when it tries to use getElementbyID. This gives me the error "91 Object variable or With block variable not set." I cannot understand what's wrong considering I can use .Navigate but not .getElementbyID!!! :banghead:
My Code:
Your help with this will be much appreciated!
Thanks
Ok, so I can currently open a new internet explorer instance, navigate to my URL, then use the .getElementByID to insert my preference into a textbox on the page. Looks like this:
Code:
Dim oIE As Object
Set oIE = CreateObject("InternetExplorer.Application")
oIE.Navigate "URL of my Choice"
Do While oIE.Busy Or oIE.ReadyState <> READYSTATE_COMPLETE
DoEvents
Loop
oIE.Document.getElementById("Surname").Value = "My Surname Here"
Now, that works fine. I want to take this a step further and use an existing internet explorer window. I can find the already existing IE window, open a new tab to same URL as previous, but I am stopped when it tries to use getElementbyID. This gives me the error "91 Object variable or With block variable not set." I cannot understand what's wrong considering I can use .Navigate but not .getElementbyID!!! :banghead:
My Code:
Code:
Function testme()
Dim objWindow As Object
Dim objIEApp As Object
Dim objShell As Object
Dim objItem As Object
Set objShell = CreateObject("Shell.Application")
Set objWindow = objShell.Windows()
For Each objItem In objWindow
Debug.Print objItem
If LCase(objItem.FullName Like "*iexplore*") Then
w.Navigate "URL of my choice" , CLng(2048)
w.Document.getElementById("Surname").Value = "My Surname Here"
got skiprest
End If
Next objItem
skiprest:
End Function
Your help with this will be much appreciated!
Thanks