[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 164
  • Last Modified:

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?
0
RunToTheHills
Asked:
RunToTheHills
  • 2
  • 2
  • 2
  • +1
1 Solution
 
Michael_DCommented:
Try:

X="C:\WINDOWS\"

Shell "explorer " & X , vbNormalFocus
0
 
BrianGEFF719Commented:


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
0
 
BrianGEFF719Commented:
forgot to include

CONST SW_SHOWMAXIMIZED = 3
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
RunToTheHillsAuthor Commented:
Michael D

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

Shell "explorerC:\WINDOWS\"  , vbNormalFocus

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

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now