Launch Windows Explorer With Specific Directory

This code will launch Windows explorer with specific directory.

Module Code

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

Public Const SW_SHOWNORMAL = 1

Form Code

Public Sub OpenExplorer(Optional InitialDirectory As String)

      ShellExecute 0, "Explore", InitialDirectory, _
        vbNullString, vbNullString, SW_SHOWNORMAL

End Sub

Private Sub Form_Load()
' Put here the directory you want to launch the explorer with
' If you want to launch Windows Explorer with the current
' default directory, replace the line below with:
' OpenExplorer

    OpenExplorer ("C:\Program Files\")
End Sub

Go Back