VBA to close WIndows Explorer

tiredofit

Well-known Member
Joined
Apr 11, 2013
Messages
1,926
Office Version
  1. 365
  2. 2019
Platform
  1. Windows
According to this thread:


this code closes a session of Windows Explorer:


Rich (BB code):
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As Any) As Long

Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

Private Const WM_CLOSE = &H10

Public Sub CloseExplorer()


CloseByClass "CabinetWClass"


End Sub

Private Sub CloseByClass(className As String)


PostMessage FindWindow("CabinetWClass", vbNullString), WM_CLOSE, 0, 0

End Sub

What I am puzzled about is this line:


Rich (BB code):
PostMessage FindWindow("CabinetWClass", vbNullString), WM_CLOSE, 0, 0


FindWindow takes two arguments, so I assume CabinetWClass and vbnullstring takes care of that but what are the three remaining arguments for, ie WM_CLOSE, 0, 0?


PostMessage requires four arguments, ie hwnd, wMsg, wParam and lParam.


Thanks


EDIT SORTED:

I missed the first argument is FindWindow.
 
Last edited:

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
The return value of the FindWindow call is a hWnd, and is used as the first argument of the PostMessage call.
 
Upvote 0

Forum statistics

Threads
1,224,822
Messages
6,181,164
Members
453,021
Latest member
Justyna P

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
Back
Top