Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Controlling already running instance of Internet Explorer

Status
Not open for further replies.

cgugler

Programmer
May 5, 2006
2
US
I've gotten to the point where I can create a new IE and make it navigate through links and fill out forms automatically, but now I'd like to be able to control an already running instance of IE and do the same. I'm having trouble figuring out how to access the already running ie window. I realize I'd have to use DDE but I'm unsure exactly how I'd do this. At this point I'm as far as finding ie with this:
Code:
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long)

Sub Main 
    thisTest = FindWindow(vbNullString, "Google - Microsoft Internet Explorer")
    
    msgbox(thisTest)
End Sub

Is it possible to make that an object that I can control as I would with a new window? (thisTest.Navigate URL)
 
This will find the first open instance of Internet Explorer and make it an object you can control.
Code:
dim objIE, objApp
set objApp = CreateObject("Shell.Application")
for i = 0 to 100
  strName = ""
  On Error Resume Next
  strName = objApp.Windows(i).Name
  if InStr(strName,"Internet") then
    set objIE = objApp.Windows(i)
    exit for
  end If
next
if objIE is nothing then
  wscript.echo "No Internet Explorer Object"
else
  objIE.Navigate("[URL unfurl="true"]www.google.com")[/URL]
end if
 
Thank you. That opened up quite a few possibilities. I ended up using the something similiar to the following code so it would find the correct IE window to use.

Code:
    dim objIE as Object, objApp as Object
    Set objApp = CreateObject("Shell.Application")
    for i = 0 to 25
        strName = ""
        On Error Resume Next
        strName = objApp.Windows(i).document.url
        if InStr(strName,"google.com") then
            set objIE = objApp.Windows(i)
            exit for
        end If
    next
    
    if objIE is nothing then
        msgbox("IE window not found")
    else
        objIE.Document.links(5).click
    end if
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top