VBA Check if Internet Explorer is already Open/Running

decadence

Well-known Member
Joined
Oct 9, 2015
Messages
524
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
  5. 2007
Platform
  1. Windows
Hi, Is there a way to check if the Internet Explorer is Open/Running, I have searched over and over but can't seem to find a solution.

The Code below is what I have so far, Can someone help Please

VBA Code:
Option Explicit
Private Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdSHow As Long) As Long
Const SW_SHOWMAXIMIZED = 3
Const URL As String = "http://www.google.co.uk/search?q="
Const GoogleSearch As String = "Microsoft"
Dim IE
Sub SearchInternet()
'Search Internet From Excel
    Set IE = CreateObject("InternetExplorer.Application")
    ''''''''''''Check if Internet is already open and if so add new tab and search in new tab
    'IE.Navigate URL & GoogleSearch, CLng(2048)
    ''''''''''''If Internet Explorer is not open then Open internet explorer and search
    IE.Navigate URL & GoogleSearch
    Do
        If IE.ReadyState = 4 Then
            IE.Visible = False
            Exit Do
        Else
            DoEvents
        End If
    Loop
    Do
        If IE.Busy Then
            IE.Visible = False
            Exit Do
        Else
            DoEvents
        End If
    Loop
    'Do While IE.ReadyState <> 4: DoEvents: Loop
    'Do While IE.Busy: DoEvents: Loop
    ShowWindow IE.hwnd, SW_SHOWMAXIMIZED
    IE.Visible = True
    Set IE = Nothing
End Sub
 

Some videos you may like

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

kennypete

Board Regular
Joined
Apr 19, 2008
Messages
243
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
This works for me. I tried after opening and closing IE and gives the right answer each time:
VBA Code:
Sub CheckIE()
    If ProcessIsRunning("iexplore.exe") Then
       MsgBox ("IE's open")
    Else
       MsgBox ("IE's closed")
    End If
End Sub

Function ProcessIsRunning(strProcess As String)
    Dim objList As Object
    Set objList = GetObject("winmgmts:") _
        .ExecQuery("select * from win32_process where name='" & strProcess & "'")
    If objList.Count > 0 Then
        ProcessIsRunning = True
    Else
        ProcessIsRunning = False
    End If
End Function
 

decadence

Well-known Member
Joined
Oct 9, 2015
Messages
524
Office Version
  1. 365
  2. 2016
  3. 2013
  4. 2010
  5. 2007
Platform
  1. Windows
Works for me too, Thanks for your help :)
 

Watch MrExcel Video

Forum statistics

Threads
1,126,993
Messages
5,622,049
Members
415,875
Latest member
Tarali

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
Top