我在使用WSH.run命令和转义filepath中的空格时遇到了问题--没有空格它工作得很好!我尝试在每个参数/ filepath周围使用双重、三重和四重引号,但是当从VBA脚本调用cmd shell时,它不喜欢filepath。这是没有任何转义的脚本:
Dim strFilePath As String
Dim xslFilePath As String
Dim RetVal
Dim wsh As Object
Set wsh = VBA.CreateObject("WScript.Shell")
firstFilePath = "C:\Program Files\myprogram.exe"
secondFilePath = "C:\Program Files\stylesheet.xsl"
strfilepath = "D:\outputfiles\out.xls"
outpath = Mid(strFilePath, InStrRev(strFilePath, "\") + 1)
outfile = Left(strFilePath, InStrRev(strFilePath, ".") - 1)
logfile = outfile & "_errors.log"
cmd1 = firstFilePath & " -s:" & strFilePath & " -xsl:" & secondFilePath & " -o:" & outfile & ".csv > " & logfile & " 2>&1"
wsh.Run "cmd /c /s" & cmd1, 2, True
当我通过带有转义文件的命令行运行下面的命令时,命令成功地完成了,所以我不确定为什么在Excel中调用相同的已应用转义时这是不工作的?
"C:\Program Files\myprogram.exe" -s:"D:\outputfiles\out.xls" -xsl:"C:\Program Files\stylesheet.xsl" -o:"D:\outputfiles\out.csv" > "D:\outputfiles\out_errors.log" 2>&1
任何建议或帮助都很感激。
发布于 2019-07-24 06:12:36
将此用于您的cmd1
行
cmd1 = """""" & firstFilePath & """ -s:""" & strFilePath & """ -xsl:""" & secondFilePath & """ -o:""" & outfile & ".csv"" > """ & logfile & """ 2>&1"""
https://stackoverflow.com/questions/57184788
复制