Excel VBA打开文件夹

San*_*nya 13 directory excel vba excel-vba excel-2010

使用2010 Excel VBA - 我只是想通过sub打开一个文件夹.我在这做错了什么?

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
Run Code Online (Sandbox Code Playgroud)

d-s*_*yer 31

如果要打开Windows文件资源管理器,则应调用explorer.exe

Call Shell("explorer.exe" & " " & "P:\Engineering", vbNormalFocus)
Run Code Online (Sandbox Code Playgroud)

等效的syxntax

Shell "explorer.exe" & " " & "P:\Engineering", vbNormalFocus
Run Code Online (Sandbox Code Playgroud)

  • 这可以通过 `Shell("explorer.exe P:\Engineering", vbNormalFocus)` 来简化。但是,如果有空格,则需要用双引号将它们括起来,两次,正如 Tim 提到的: `Shell("explorer.exe ""P:\Engineering\031 Electronic Job Folders""", vbNormalFocus)` (2认同)