Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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
like image 556
2 revs Avatar asked Jul 02 '13 13:07

2 revs


People also ask

How do you use Excel to open a folder?

After clicking the Enterprise > Workbook Tools > Open Containing Folder, it opens current workbook's containing folder. What's more, current workbook is selected in the document folder.


1 Answers

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
like image 184
d-stroyer Avatar answered Sep 19 '22 17:09

d-stroyer