vba - test ie object

by using below, the website is open in IE. After manually close it, ie is still an object but not containing any variable anymore. How to test it to find out if IE has been closed or not? Thanks.

Set ie = CreateObject("internetexplorer.application")

ie.navigate(http://website)

January 31st, 2015 9:17am

Here's a little snippit that you can use... adjust to your own needs

Sub OpenIE()
Set IE = CreateObject("InternetExplorer.Application")

IE.navigate ("your site here")

IE.Visible=true

' do something here
' use quit to stop IE
' IE.quit

Set IE = Nothing
End Sub

Free Windows Admin Tool Kit Click here and download it now
January 31st, 2015 9:43am

Sorry, I may not explain clear.

After website open in Internet Explorer, the script does not close it but needs to monitor to keep it open. If IE window is closed by user manually, the script needs to find it and reopen IE.

I tried to use IsObject, IsNull, ValueType and so on, nothing work.

I need to test IE something like:

If IE window closed by user manually Then

  Release ie variable (because it is not valid anymore)

  Set ie = CreateObject("InternetExplorer.Application")

  ie
.navigate ("your site here")

  ie
.Visible=true

End If


  • Edited by Ian3 17 hours 13 minutes ago
January 31st, 2015 9:58am

Sorry, I may not explain clear.

After website open in Internet Explorer, the script does not close it but needs to monitor to keep it open. If IE window is closed by user manually, the script needs to find it and reopen IE.

I tried to use IsObject, IsNull, ValueType and so on, nothing work.

I need to test IE something like:

If IE window closed by user manually Then

  Release ie variable (because it is not valid anymore)

  Set ie = CreateObject("InternetExplorer.Application")

  ie
.navigate ("your site here")

  ie
.Visible=true

End If


  • Edited by Ian3 Saturday, January 31, 2015 3:08 PM
Free Windows Admin Tool Kit Click here and download it now
January 31st, 2015 2:56pm

Sorry, I may not explain clear.

After website open in Internet Explorer, the script does not close it but needs to monitor to keep it open. If IE window is closed by user manually, the script needs to find it and reopen IE.

I tried to use IsObject, IsNull, ValueType and so on, nothing work.

I need to test IE something like:

If IE window closed by user manually Then

  Release ie variable (because it is not valid anymore)

  Set ie = CreateObject("InternetExplorer.Application")

  ie
.navigate ("your site here")

  ie
.Visible=true

End If


  • Edited by Ian3 Saturday, January 31, 2015 3:08 PM
January 31st, 2015 5:56pm

I use the following function. Hope it helps.

Function Get_existing_IE() As InternetExplorer
    Dim found_IE As Boolean
    Dim shellWins As SHDocVw.ShellWindows
    Dim explorer As SHDocVw.InternetExplorerMedium

    Set shellWins = New SHDocVw.ShellWindows
    'try to find an Internet Explorer window already connected to a specific URL
    For Each explorer In shellWins
        If InStr(explorer.LocationURL, " type your URL") > 0 Then
            Set Get_existing_IE = explorer
            found_IE = True
            Exit For
        End If
    Next

    Set shellWins = Nothing
    Set explorer = Nothing

    If Not found_PDM_IE Then    ' create one
        Set Get_existing_IE = New InternetExplorerMedium
    End If

End Function

Free Windows Admin Tool Kit Click here and download it now
February 2nd, 2015 4:22am

I use the following function. Hope it helps.

Function Get_existing_IE() As InternetExplorer
    Dim found_IE As Boolean
    Dim shellWins As SHDocVw.ShellWindows
    Dim explorer As SHDocVw.InternetExplorerMedium

    Set shellWins = New SHDocVw.ShellWindows
    'try to find an Internet Explorer window already connected to a specific URL
    For Each explorer In shellWins
        If InStr(explorer.LocationURL, " type your URL") > 0 Then
            Set Get_existing_IE = explorer
            found_IE = True
            Exit For
        End If
    Next

    Set shellWins = Nothing
    Set explorer = Nothing

    If Not found_PDM_IE Then    ' create one
        Set Get_existing_IE = New InternetExplorerMedium
    End If

End Function

February 2nd, 2015 9:20am

I've been looking for this same issue for a few days now. In summary the order is this:

we create a new internetexplorer object

we navigate to a URL using that object

we pause for some user intervention (in my case the user needs to enter a password)

We want to check if the dopey user has closed the ie instance as any reference to that ie object afterwards would generate error 426

If ie has been closed, we bail out; if ie hasn't, we carry on processing the web elements

close and quit everything nicely

While Maurice's code gets close to this by checking for an IE instance with a matching url, it's not quite the same as saying is my ie object still valid? Unfortunately any reference to the ie object after it was closed generates error 426. Like the op, I tried resting for ie isnothing and null but it all generates the error.

Any offers?

Thank you in advance

Pete

Free Windows Admin Tool Kit Click here and download it now
August 17th, 2015 12:46pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics