Consulting

Results 1 to 5 of 5

Thread: Solved: Close all instances of IE

  1. #1
    VBAX Contributor
    Joined
    Dec 2004
    Posts
    122
    Location

    Solved: Close all instances of IE

    Hi everybody, if you could help me, I would like to add a command button on a userform that will close all instances of Internet Explorer with out close the user form. I tryed to search for the answer here and in google but I can not find it. I had it once a long time ago but lost it. If anybody could help, I would greatly appreciate it. Thanks in advance.

  2. #2
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    You could use something like this:
    [VBA]Sub FindAndTerminate(ByVal strProcName As String)
    Dim objWMIService, objProcess, colProcess
    Dim strComputer, strList
    strComputer = "."
    Set objWMIService = GetObject("winmgmts:" _
    & "{impersonationLevel=impersonate}!\\" _
    & strComputer & "\root\cimv2")
    Set colProcess = objWMIService.ExecQuery _
    ("Select * from Win32_Process Where Name = '" & strProcName & "'")
    If colProcess.Count > 0 Then
    For Each objProcess In colProcess
    objProcess.Terminate
    Next objProcess
    End If
    End Sub
    [/VBA]
    just pass "IExplore.exe" as the argument.
    Regards,
    Rory

    Microsoft MVP - Excel

  3. #3
    VBAX Contributor
    Joined
    Dec 2004
    Posts
    122
    Location
    I can't figure out how to make this work, I have tryed everything. Maybe you can go a little further and show me how to do this so it will work. Thanks for your help

  4. #4
    VBAX Master
    Joined
    Jun 2007
    Location
    East Sussex
    Posts
    1,110
    Location
    Put that code into a normal module in your project, then in the Click event of your button, you would just use:
    [VBA]findandterminate "IExplore.exe"[/VBA]
    Regards,
    Rory

    Microsoft MVP - Excel

  5. #5
    VBAX Contributor
    Joined
    Dec 2004
    Posts
    122
    Location

    It works,

    thanks alot for your help and time.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •