PC Review


Reply
Thread Tools Rate Thread

Close all internet explorer windows

 
 
ajbarilla@gmail.com
Guest
Posts: n/a
 
      5th Jul 2007
Is there a way to close all open internet explorer windows from Excel
VBA. I am able to write the code to close the windows that my code
opens, but I cant get it to close the windows that were already open
prior to running the code. If you can't close them from Exel VBA
code, can you check if any are open.

Thanks for your help

 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      5th Jul 2007
Try code like the following:

Option Explicit

Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
ByVal HWnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long

Public Const WM_CLOSE As Long = &H10
Public Const IE_WINDOW_CLASS = "IEFrame"


Sub CloseAllInternetExplorer()

Dim HWnd As Long
HWnd = FindWindow(IE_WINDOW_CLASS, vbNullString)
Do Until HWnd = 0
SendMessage HWnd, WM_CLOSE, 0&, 0&
HWnd = FindWindow(IE_WINDOW_CLASS, vbNullString)
Loop

End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is there a way to close all open internet explorer windows from Excel
> VBA. I am able to write the code to close the windows that my code
> opens, but I cant get it to close the windows that were already open
> prior to running the code. If you can't close them from Exel VBA
> code, can you check if any are open.
>
> Thanks for your help
>


 
Reply With Quote
 
Chip Pearson
Guest
Posts: n/a
 
      5th Jul 2007
I should have noted that the code I posted will not work properly for IE7 if
the "close tabs" confirmation dialog is set to display when IE7 closes.


--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting
www.cpearson.com
(email on the web site)

"Chip Pearson" <(E-Mail Removed)> wrote in message
news:FBDC5BC0-5074-4DF7-915C-(E-Mail Removed)...
> Try code like the following:
>
> Option Explicit
>
> Public Declare Function FindWindow Lib "user32" Alias "FindWindowA" ( _
> ByVal lpClassName As String, _
> ByVal lpWindowName As String) As Long
>
> Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
> ByVal HWnd As Long, _
> ByVal wMsg As Long, _
> ByVal wParam As Long, _
> lParam As Any) As Long
>
> Public Const WM_CLOSE As Long = &H10
> Public Const IE_WINDOW_CLASS = "IEFrame"
>
>
> Sub CloseAllInternetExplorer()
>
> Dim HWnd As Long
> HWnd = FindWindow(IE_WINDOW_CLASS, vbNullString)
> Do Until HWnd = 0
> SendMessage HWnd, WM_CLOSE, 0&, 0&
> HWnd = FindWindow(IE_WINDOW_CLASS, vbNullString)
> Loop
>
> End Sub
>
>
> --
> Cordially,
> Chip Pearson
> Microsoft MVP - Excel
> Pearson Software Consulting
> www.cpearson.com
> (email on the web site)
>
>
> <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> Is there a way to close all open internet explorer windows from Excel
>> VBA. I am able to write the code to close the windows that my code
>> opens, but I cant get it to close the windows that were already open
>> prior to running the code. If you can't close them from Exel VBA
>> code, can you check if any are open.
>>
>> Thanks for your help
>>

>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: All of my Internet Explorer windows close when I close just one smlunatick Windows XP Help 0 27th Dec 2006 06:06 PM
all internet explorer windows close if i close 1 =?Utf-8?B?c3RldmU=?= Windows XP Help 0 27th Nov 2005 10:07 PM
Close windows Internet Explorer Oscar Diaz Microsoft Windows 2000 Group Policy 0 23rd Jan 2004 02:04 PM
Can't close some Internet Explorer windows Jason Windows XP General 2 18th Aug 2003 06:51 AM
Can't close some Internet Explorer Windows Jason Windows XP General 0 18th Aug 2003 03:40 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:34 PM.