Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 92
Default How to Show Existing IE Instance if Already Exists, Else Open One

Set the reference like Chip said, then here is another version of code that
should do what you want. Replace "Google" with the page you are using.

Public Sub CheckIE()
Dim objSW As SHDocVw.ShellWindows
Dim objIE As SHDocVw.InternetExplorer
Dim objDoc As Object
Dim bAppRunning As Boolean

'Set objSW = New SHDocVw.ShellWindows
If objSW.Count Then ' new
For Each objDoc In objSW
If InStr(1, objDoc.LocationName, "Google") Then
bAppRunning = True
objDoc.Visible = True
Exit For
End If
Next objDoc
End If
If bAppRunning = False Then
Set objIE = CreateObject("InternetExplorer.Application") ' new
objIE.Visible = True
objIE.Navigate "www.google.com"
End If

Set objIE = Nothing
Set objSW = Nothing
End Sub

Paul D

wrote in message
oups.com...
: Hi folks,
: I'm trying to do the following:
:
: Test to see if Internet Explorer already has an instance open to address
"www.mypage.com", for instance.
: If it is already open, then change focus to that existing window.
: If it is not already open, then start a new instance of IE with that
URL.
:
: I've got many years as a programmer, but new to this language. I did
: find the following code that looks close to what I want, but I get an
: error msg that reads: "User-defined type not defined" - referencing the
:
: variable "objSW As SHDocVw.ShellWindows"
:
: Here is the code I found:
:
:
: Dim objSW As SHDocVw.ShellWindows
: Dim objIE As SHDocVw.InternetExplorer
: Dim objDoc As Object
:
:
: Set objSW = New SHDocVw.ShellWindows
: If objSW.Count Then ' new
: For Each objIE In objSW
: If InStr(1, objIE.FullName, "mypage") Then
: Set objIE = objSW.Item
: fAppRunning = True
: Exit For
: Else
: Set objIE = CreateObject("InternetExplorer.Application")
: End If
: Next objIE
: Else ' new
: Set objIE = CreateObject("InternetExplorer.Application") ' new
: End If
:
:
: objIE.Visible = True
:
:
: objIE.Navigate "www.mypage.com"
:
:
: Set objDoc = Nothing
: Set objIE = Nothing
: Set objSW = Nothing
:
:
: THANK YOU in advance for your help. GREATLY APPRECIATED!
: Kind regards,
: Cole
:


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Show it here, if it exists there Kevin Excel Discussion (Misc queries) 5 July 28th 07 06:21 PM
How to Show Existing IE Instance if Already Exists, Else Open One Cole Excel Discussion (Misc queries) 0 June 9th 06 07:35 PM
Connecting to an existing IE instance. J Streger Excel Programming 0 April 10th 06 10:33 PM
Taking control of an existing instance of Excel nmventure Excel Programming 10 November 6th 05 03:13 PM
Get an object representing an existing Excel instance from Outlook R Avery Excel Programming 1 August 25th 04 11:16 PM


All times are GMT +1. The time now is 07:47 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"