Search code examples
vbaexceldirectoryexcel-2010

Excel VBA Open a Folder


Using 2010 Excel VBA - I'm just trying to open a folder through a sub. What am I doing wrong here?

VBA

Sub openFolder()  
  Dim preFolder As String, theFolder As String, fullPath as String

    theFolder = Left(Range("T12").Value, 8)
    preFolder = Left(Range("T12").Value, 5) & "xxx"
    fullPath = "P:\Engineering\031 Electronic Job Folders\" & preFolder & "\" & theFolder

    Shell(theFolder, "P:\Engineering\031 Electronic Job Folders\" & preFolder, vbNormalFocus)

End Sub

Solution

  • If you want to open a windows file explorer, you should call explorer.exe

    Call Shell("explorer.exe" & " " & "P:\Engineering", vbNormalFocus)
    

    Equivalent syxntax

    Shell "explorer.exe" & " " & "P:\Engineering", vbNormalFocus