Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 172
Default Close an Internet Explorer browser window

I'm using a variation of this code from a posting by Chip Pearson to
try to close a browser window that I opened. The code works fine when
I use it with Notepad (closes the Notepad window that I opened), but
fails to close the Internet Explorer window (fails to close a browser
that I opened).

FindWindow is retrieving the handle correctly. SendMessage is at
fault. If I substitute PostMessage for SendMessage, then the browser
closes.

Just curious as to why. Any insights?

http://www.google.com/groups?hl=en&l...8ecc7fb&rnum=2

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 Declare Function FindWindow Lib "user32" Alias "FindWindowA"
_
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Sub CloseCalc()
On Error Resume Next
Dim hWnd As Long
Const WM_CLOSE = &H10
hWnd = FindWindow(vbNullString, "Calculator")
If hWnd 0 Then
SendMessage hWnd, WM_CLOSE, 0&, 0&
End If
End Sub

Many thanks in advance for any and all responses.

Paul

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Close an Internet Explorer browser window

Paul,

I can't explain why your code doesn't quit IE, looks as if
it should. However if you're also doing other things with
your instance of IE, maybe try something like this as a
different approach:

First set reference to
"Microsoft Internet Controls"
(Tools / References)

Sub test()
Dim IEApp As SHDocVw.InternetExplorer
Set IEApp = New SHDocVw.InternetExplorer
IEApp.Visible = True

'code
'look in Object Browser, library SHDocVw

IEApp.Quit
Set IEDocument = Nothing
Set IEApp = Nothing

End Sub

I'm new to "SHDocVw" so test thoroughly (Dick Kusleika got
me started with it earlier this year).

Regards,
Sandy



-----Original Message-----
I'm using a variation of this code from a posting by Chip

Pearson to
try to close a browser window that I opened. The code

works fine when
I use it with Notepad (closes the Notepad window that I

opened), but
fails to close the Internet Explorer window (fails to

close a browser
that I opened).

FindWindow is retrieving the handle correctly.

SendMessage is at
fault. If I substitute PostMessage for SendMessage, then

the browser
closes.

Just curious as to why. Any insights?

http://www.google.com/groups?hl=en&lr=lang_en&ie=UTF-

8&c2coff=1&safe=off&th=30d9d56bb8ecc7fb&rnum=2

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 Declare Function FindWindow Lib "user32"

Alias "FindWindowA"
_
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Sub CloseCalc()
On Error Resume Next
Dim hWnd As Long
Const WM_CLOSE = &H10
hWnd = FindWindow(vbNullString, "Calculator")
If hWnd 0 Then
SendMessage hWnd, WM_CLOSE, 0&, 0&
End If
End Sub

Many thanks in advance for any and all responses.

Paul

.

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
Send Key to open a particular internet browser sunspot27 Excel Worksheet Functions 0 July 16th 09 12:31 PM
Docking Project Explorer, Properties window and Code window in VBE jayray Setting up and Configuration of Excel 2 March 27th 07 04:42 PM
Close explorer window from excel VBA Itzik[_2_] Excel Programming 0 October 1st 03 02:58 PM
Close Browser window with VBA brianelson Excel Programming 1 July 12th 03 05:35 AM


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

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

About Us

"It's about Microsoft Excel"