使用路径

时间:2018-04-29 23:32:26

标签: excel-vba shell file vba excel

在过去的几天里,我一直在尝试使用Shell()

通过VBA打开文件

我的问题是我的路径在路径中有括号:c:/ xxx /(xxx)/ xxx

任何帮助都将不胜感激,谢谢。

Sub OpenMyFolder()

    Dim myFolder As String

    myFolder = "C:\Users\MrSmith\Dropbox (Personal)\Photos\2018"

    myFolder = myFolder & "\Jan"

    Shell "explorer.exe" & " " & myFolder, vbNormalFocus

End Sub

1 个答案:

答案 0 :(得分:0)

将任何带空格的路径传递给Shell时,应将其括在引号中:

Sub OpenMyFolder()

    Dim myFolder As String

    myFolder = "C:\Users\MrSmith\Dropbox (Personal)\Photos\2018"

    myFolder = myFolder & "\Jan"

    Shell "explorer.exe """ & myFolder & """", vbNormalFocus

End Sub

VBA字符串中的引号应该加倍以逃避它们(即所以引号不会被解释为字符串的开头/结尾)