Connecting Tech Pros Worldwide Forums | Help | Site Map

How do I close Windows Explorer using Access VBA

Newbie
 
Join Date: Aug 2007
Posts: 2
#1: Aug 22 '07
I have a form that allows users to open Windows Explorer and view folders based on a list of path names.

I want to create code that will close all or a specific Windows Explorer screen.

I used this line to open the Windows Explorer

Application.FollowHyperlink strPathName, , False, False

How do I close Windows Explorer?

Thanks
FishVal's Avatar
Expert
 
Join Date: Jun 2007
Location: Israel
Posts: 2,584
#2: Aug 22 '07

re: How do I close Windows Explorer using Access VBA


Quote:

Originally Posted by jercha

I have a form that allows users to open Windows Explorer and view folders based on a list of path names.

I want to create code that will close all or a specific Windows Explorer screen.

I used this line to open the Windows Explorer

Application.FollowHyperlink strPathName, , False, False

How do I close Windows Explorer?

Thanks

Hi, jercha.

If you will manage to run WinExplorer via "Shell" function, then the following will be useful for you
Close a Program
Newbie
 
Join Date: Aug 2007
Posts: 2
#3: Aug 23 '07

re: How do I close Windows Explorer using Access VBA


Quote:

Originally Posted by FishVal

Hi, jercha.

If you will manage to run WinExplorer via "Shell" function, then the following will be useful for you
Close a Program


Your notepad program worked for notepad but not for explorer.
How do I fix?

I replaced notepad with explorer but the CloseProcess failed to close the explorer screen:


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 GetWindowThreadProcessId Lib "user32" _
(ByVal hWnd As Long, ByRef lpdwProcessId As Long) As Long


Public Declare Function EnumWindows Lib "user32" _
(ByVal fpCallback As Long, ByVal lParam As Long) As Long

Public Const WM_CLOSE = 16

Public Sub RunAndCloseApp()
Dim lngProcID As Long
lngProcID = Shell("explorer")
MsgBox "Explorer started, Ok to close it", vbOKOnly, "Close App"
CloseProcess lngProcID
End Sub

Public Sub clbEnumWindows(ByVal hWnd As Long, ByVal lngParam As Long)
Dim lngProcID As Long
GetWindowThreadProcessId hWnd, lngProcID
If lngProcID = lngParam Then
'Debug.Print hWnd, lngProcID
SendMessage hWnd, WM_CLOSE, 0, 0
End If
End Sub

Public Sub CloseProcess(ByVal lngProcID)
EnumWindows AddressOf clbEnumWindows, lngProcID
End Sub

Reply