简体   繁体   English

VBA执行函数,在参数cmd.exe中带有多个引号

[英]VBA execute function with several quotation marks in parameters cmd.exe

Here is a syntax error. 这是语法错误。 How to properly run the ShellWait function? 如何正确运行ShellWait函数? I care about double quotes being used. 我关心使用双引号。 The boolean parameter should be able to be changed to false. 布尔参数应该可以更改为false。 I do not use VBA every day so I am asking for an example if you can. 我不是每天都使用VBA,所以我想问一个例子。

Sub ShellWait(fName As String, Optional showWindow As Boolean = True)
    Dim wsh As Object
    Set wsh = VBA.CreateObject("WScript.Shell")
    wsh.Run fName, -showWindow, True
End Sub

Private Sub Document_close()
    ShellWait "cmd /c echo ^<meta http-equiv="x-ua-compatible" content="IE=10"^> && echo '"hello"' "
    ' ^the above code does not work
    ShellWait "cmd /c echo '"hello"' "
    ' ^the above code does not work, syntax error
    ShellWait (cmd /c echo '"hello"')
    ' ^the above code does not work, syntax error
End Sub

您可以使用以下内容

ShellWait "cmd /K echo ^<meta http-equiv=""x-ua-compatible"" content=""IE=10""^> && echo '""hello""' "

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM