shell命令使用带空格的变量

时间:2016-01-15 17:39:00

标签: vba shell pdf

Public Sub test()

Dim path As String
path1 = "C:\File Folder\File Test.pdf"
path2 = "C:\FileFolder\FileTest.pdf"
Shell "C:\Program Files (x86)\Nuance\PDF Professional 8\bin\GaaihoDoc.exe " & path1, vbNormalFocus

End Sub

由于path2变量中的空格,如果使用path1变量而不是path1,则VBA中的上述代码有效。如何修复以运行变量path1

1 个答案:

答案 0 :(得分:0)

带空格的路径需要引用双引号。 通过将它们加倍来逃避报价:

path1 = "C:\File Folder\File Test.pdf"
Shell """C:\Program Files (x86)\Nuance\PDF Professional 8\bin\GaaihoDoc.exe"" """ & path1 & """", vbNormalFocus