How to Open a Folder in Windows Explorer using VBA
ShellExecute() Windows API function can be called from a VBA macro to start another program under Microsoft Windows. Use ShellExecute() instead of Shell (a Visual Basic statement) or WinExec() (a Windows API function) to work around the following limitation of the latter commands.
With Shell and WinExec(), you cannot start an application by specifying a file name only. For example, the following Shell statement will fail:
Shell (“c:\temp”)
Declare the API function
Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation _
As String, ByVal lpFile As String, ByVal lpParameters _
As String, ByVal lpDirectory As String, ByVal nShowCmd _
As Long) As Long
The following code will open the specified folder in Windows Explorer
Sub Open_ExplorerWindow()
ShellExecute 0, "open", "c:\temp", 0, 0, 1