Connect to running instance of internet explorer with vba

ssu02193

New Member
Joined
Jul 4, 2012
Messages
20
Hi - i'm trying to connect to a running instance of ie 7 and/or 8 from excel 2007 using vba. Plenty of examples to open a new page, but I'm not finding any that work to go to an existing one.

the code at http://support.microsoft.com/kb/q176792 requires a object definition that I can't master, perhaps it's old?

there's also a page here, http://www.mrexcel.com/forum/showthread.php?553580-VBA-Macro-For-Already-Open-IE-Window, I've tried each of the top three example and when I run them, there's no action - no bringing the ie age to the front and no error message.

any thoughts would be most helpful.

Thanks!
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
I've been trying the same too.....Page gets openend.....but no luck for entering the username in text box........Please do share if you make any progress....
 
Upvote 0
Hi, :)

the following works fine for me - but with the Internet Explorer 9:

Code:
Option Explicit
Const strTMP As String = "Excel VBA"
Public Sub Test()
    Dim objWindow As Object
    Dim objIEApp As Object
    Dim objShell As Object
    Dim objItem As Object
    On Error GoTo Fin
    Set objShell = CreateObject("Shell.Application")
    Set objWindow = objShell.Windows()
    For Each objItem In objWindow
        If LCase(objItem.FullName Like "*iexplore*") Then
            Set objIEApp = objItem
        End If
    Next objItem
    If objIEApp Is Nothing Then
        Set objIEApp = CreateObject("InternetExplorer.Application")
        objIEApp.Visible = True
    End If
    With objIEApp
        .Visible = True
        .Navigate "http://www.google.com"
        While Not .ReadyState = 4
            DoEvents
        Wend
        .Document.all.q.Value = strTMP
        .Document.Forms(0).submit
    End With
Fin:
    If Err.Number <> 0 Then MsgBox "Error: " & _
        Err.Number & " " & Err.Description
    Set objWindow = Nothing
    Set objShell = Nothing
End Sub
 
Upvote 0
Thanks Case-Germany, this is getting pretty close! Really appreciate your help. Two things. First, this refreshes the ie page which isn’t necessarily a bad thing, but it doesn’t bring it forward or make it the active application. Second, it gives me: Error: 438 Object doesn’t support this property or method.
If it matters, this a work computer and I can reference Microsoft HTML Object Library but not Microsoft Internet Tools. I don’t find Shdocvw.dll anywhere on my c drive and I’m showing hidden and system files. Can’t do much with registry w/o being an admin.
Any ideas?
Thanks again, appreciate your help because I’ve been struggling to figure this out for too long.
 
Upvote 0
Thanks Case-Germany, this is getting pretty close! Really appreciate your help. Two things. First, this refreshes the ie page which isn’t necessarily a bad thing, but it doesn’t bring it forward or make it the active application. Second, it gives me: Error: 438 Object doesn’t support this property or method.
If it matters, this a work computer and I can reference Microsoft HTML Object Library but not Microsoft Internet Tools. I don’t find Shdocvw.dll anywhere on my c drive and I’m showing hidden and system files. Can’t do much with registry w/o being an admin.
Any ideas?
Thanks again, appreciate your help because I’ve been struggling to figure this out for too long.
 
Upvote 0
Hi, :)

with the following API function you can get Internet Explorer to the foreground:

"ShowWindow"

Code:
Option Explicit
Private Declare Sub ShowWindow Lib "user32" _
    (ByVal hWnd As Long, ByVal nCmdShow As Long)
Const strTMP As String = "Excel VBA"
Private Const SW_MAXIMIZE = 3
Public Sub Test()
    Dim objWindow As Object
    Dim objIEApp As Object
    Dim objShell As Object
    Dim objItem As Object
    On Error GoTo Fin
    Set objShell = CreateObject("Shell.Application")
    Set objWindow = objShell.Windows()
    For Each objItem In objWindow
        If LCase(objItem.FullName Like "*iexplore*") Then
            Set objIEApp = objItem
        End If
    Next objItem
    If objIEApp Is Nothing Then
        Set objIEApp = CreateObject("InternetExplorer.Application")
        objIEApp.Visible = True
    End If
    With objIEApp
        .Visible = True
        ShowWindow .hWnd, SW_MAXIMIZE
        '.Navigate "http://www.google.com"
        'While Not .ReadyState = 4
        '    DoEvents
        'Wend
        '.Document.all.q.Value = strTMP
        '.Document.Forms(0).submit
    End With
Fin:
    If Err.Number <> 0 Then MsgBox "Error: " & _
        Err.Number & " " & Err.Description
    Set objWindow = Nothing
    Set objShell = Nothing
End Sub

Dll files can be found here:

DLL

Registration will be problematic on a business PC.
 
Upvote 0

Forum statistics

Threads
1,214,826
Messages
6,121,794
Members
449,048
Latest member
greyangel23

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top