Link to home
Start Free TrialLog in
Avatar of RunToTheHills
RunToTheHills

asked on

Open a folder with code

I would like to open a folder thru code

X="C:\WINDOWS\"
Shell X

this does not work

am i going about this the wrong way?
ASKER CERTIFIED SOLUTION
Avatar of Michael_D
Michael_D
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial


Private 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 Sub ExploreFolder(FolderName As String)
    On Error Resume Next
    Dim X As Long
    X = ShellExecute(0&, "Explore", FolderName, 0&, 0&, SW_SHOWMAXIMIZED)
End Sub


Usage:

Call ExploreFolder("c:\windows")


Good Luck
-Brian
forgot to include

CONST SW_SHOWMAXIMIZED = 3
Avatar of RunToTheHills
RunToTheHills

ASKER

Michael D

your code works fine just wondering why i need the space after explorer before the last quotation
Because this space divides command and parameter:
Actually should be "C:\WINDOWS\explorer.exe" & Space(1) & FolderName
Because otherwise your command would be

Shell "explorerC:\WINDOWS\"  , vbNormalFocus

explorer is the program, X, or "C:\Windows" is a command line argument
thank you