I have been using a modified version of the code found under "Automate Web forms with IE" posted on the 10th of December
My question is How can I use the same process without using Set IE = CreateObject("InternetExplorer.Application") as Internet Explorer is already running and the correct web page is already displayed.
Original Code from Forum
VBSTART
Dim IE
Sub CreateIE
Set IE = CreateObject("InternetExplorer.Application")
IE.Visible=1
End Sub
Sub Navigate(URL)
IE.Navigate URL
do while IE.Busy
loop
End Sub
Sub KillIE
IE.Quit
Set IE = nothing
End Sub
Sub WebFormFill(fieldname,fieldvalue,submit)
Dim FormNr
Dim ItemNr
Dim TheForm
if IE.Document.All.Tags("FORM").Length = 0 then
MsgBox("No form found in page")
else
for FormNr = 0 to IE.Document.Forms.Length - 1
Set TheForm = IE.Document.Forms(FormNr)
for ItemNr = 0 to TheForm.Elements.Length - 1
if TheForm.Elements(ItemNr).Name = fieldname then
TheForm.Elements(ItemNr).Value = fieldvalue
If submit=1 then
TheForm.submit
end if
exit for
end if
next
next
end if
End Sub
Retrieving Elements From a web Form
Moderators: Dorian (MJT support), JRL
You can't. GetObject lets you "get" an already running object, but, alas, Internet Explorer does not support it.
MJT Net Support
[email protected]
[email protected]
Actually, I've found a workaround to getting an already running IE object. This function enumerates IE windows. I've written this to find a running IE instance with the given URL. You could modify this if you're just looking for any old IE instance and have it stop when it finds the first one, or put each one in an array .. or whatever. This version finds the instance with the given URL. To test this open a copy of IE and navigate to http://www.mjtnet.com/ and then run this script. It will find the IE instance and navigate it to google.com:
VBSTART
Dim IE
Function GetIE(sURL)
GetIE = 0
set shellApp = createobject("shell.application")
for each w in shellApp.windows
if lcase(typename(w.document)) = "htmldocument" then
if w.LocationURL = sURL then
Set IE = w
GetIE = 1
end if
end if
next
set shellApp = nothing
End Function
Sub Navigate(sURL)
IE.Navigate sURL
do while IE.Busy
loop
End Sub
VBEND
VBEval>GetIE("http://www.mjtnet.com/"),success
If>success=1
VBRun>Navigate,http://www.google.com/
EndIf
Hope this helps.
VBSTART
Dim IE
Function GetIE(sURL)
GetIE = 0
set shellApp = createobject("shell.application")
for each w in shellApp.windows
if lcase(typename(w.document)) = "htmldocument" then
if w.LocationURL = sURL then
Set IE = w
GetIE = 1
end if
end if
next
set shellApp = nothing
End Function
Sub Navigate(sURL)
IE.Navigate sURL
do while IE.Busy
loop
End Sub
VBEND
VBEval>GetIE("http://www.mjtnet.com/"),success
If>success=1
VBRun>Navigate,http://www.google.com/
EndIf
Hope this helps.
MJT Net Support
[email protected]
[email protected]