Excel VBA Open a Folder

Sanya picture Sanya · Jul 2, 2013 · Viewed 130.9k times · Source

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

Answer

d-stroyer picture d-stroyer · Jul 2, 2013

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