在 VBA 中处理文件路径中的空间 [英] Dealing with space in file path in VBA
本文介绍了在 VBA 中处理文件路径中的空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我尝试在 cmd
中运行以下 VBA 代码.路径中有一个空格,我正在使用引号来处理它.
I have the below VBA code that I'm trying to run in cmd
. There is a space in the path and I'm using quotes to deal with that.
strWot2Shell = """C:\Program Files\gs\gs9.20\bin\gswin64.exe""" & " -dBATCH -dNOPAUSE -sDEVICE=png16m -r600 -sOutputFile=" & Chr(34) & ripDirectory & "\LagerRiskRapport%01d.png" & Chr(34) & " " & Chr(34) & filePathAndFileName & Chr(34)
strWot2Shell = Replace(strWot2Shell, "\", "/")
strWot2Shell2 = "cmd.exe /S /C " & strWot2Shell
wsh.Run strWot2Shell2, windowStyle, waitOnReturn
代码输出如下:
cmd.exe /S /C "C:/Program Files/gs/gs9.20/bin/gswin64.exe" -dBATCH -dNOPAUSE -sDEVICE=png16m -r600 -sOutputFile="G:/Rip/LagerRiskRapport%01d.png" "G:/LagerRiskRapport.pdf"
当我在 cmd
中运行这个目录时,我得到:
When I run this direclty in cmd
I get:
'C:/Program' is not recognized as an internal or external command,
operable program or batch file.
如果我直接在 cmd
下面运行它就可以了
If I run below directly in cmd
it works
"C:/Program Files/gs/gs9.20/bin/gswin64.exe" -dBATCH -dNOPAUSE -sDEVICE=png16m -r600 -sOutputFile="G:/Rip/LagerRiskRapport%01d.png" "G:/LagerRiskRapport.pdf"
像这样三重引用所有字符串:
Triple quoting all string like this:
strWot2Shell = """C:\Program Files\gs\gs9.20\bin\gswin64.exe""" & """ -dBATCH -dNOPAUSE -sDEVICE=png16m -r600 -sOutputFile=""" & Chr(34) & ripDirectory & """\LagerRiskRapport%01d.png""" & Chr(34) & " " & Chr(34) & filePathAndFileName & Chr(34)
给出这个输出:
cmd.exe /S /C "C:/Program Files/gs/gs9.20/bin/gswin64.exe"" -dBATCH -dNOPAUSE -sDEVICE=png16m -r600 -sOutputFile=""G:/Rip"/LagerRiskRapport%01d.png"" "G:/LagerRiskRapport.pdf"
将cmd.exe/S/C
括在引号中,例如"cmd.exe/S/C"
导致系统找不到指定的路径代码>.
Surrounding cmd.exe /S /C
in quotes like"cmd.exe /S /C"
results in The system cannot find the path specified
.
为什么引号不起作用?
推荐答案
这可能是因为您在开头和结尾都引用了三重引号.所以尝试改变这个:
This may be because you are triple quoting at the beginning and then not at the end. So try changing this:
"""C:\Program Files\gs\gs9.20\bin\gswin64.exe""" & " -dBATCH -dNOPAUSE -sDEVICE=png16m -r600 -sOutputFile=" & Chr(34) & ripDirectory & "\LagerRiskRapport%01d.png" & Chr(34) & " " & Chr(34) & filePathAndFileName & Chr(34)
致:
"""C:\Program Files\gs\gs9.20\bin\gswin64.exe""" & "" -dBATCH -dNOPAUSE -sDEVICE=png16m -r600 -sOutputFile="" & Chr(34) & ripDirectory & ""\LagerRiskRapport%01d.png"" & Chr(34) & " " & Chr(34) & filePathAndFileName & Chr(34)
这篇关于在 VBA 中处理文件路径中的空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文