Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Close all internet explorer windows

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Close all internet explorer windows

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)


wrote in message
oups.com...
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


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Close all internet explorer windows

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" wrote in message
...
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)


wrote in message
oups.com...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excel 2002 - Internet Explorer Windows opening up uncontrollably Mr. Low Excel Discussion (Misc queries) 0 November 3rd 06 02:19 PM
Excel 2002 - Internet Explorer Windows opening up uncontrollably Mr. Low Excel Worksheet Functions 0 November 3rd 06 01:25 PM
Windows Explorer maximizes over XL 2000, if opened w/ explorer bill Excel Discussion (Misc queries) 2 June 28th 05 02:53 PM
Close an Internet Explorer browser window [email protected] Excel Programming 1 July 5th 04 06:25 PM
Use Windows Script to run Windows Explorer Search? Ian Elliott[_3_] Excel Programming 0 January 12th 04 05:03 PM


All times are GMT +1. The time now is 09:43 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"