【问题标题】:Starting VBScript from Access VBA从 Access VBA 启动 VBScript
【发布时间】:2015-11-22 06:01:18
【问题描述】:

我正在尝试调用 VBScript 以从 Access VBA 函数中以 32 位启动。我尝试了几种不同的 Shell 变体,但似乎没有任何效果,这是我最近的尝试:

Function callVS()
    Dim wsh As Object
    Set wsh = CreateObject("Wscript.Shell")
    Dim errorCode As Integer
    errorCode = wsh.Run("C:\Windows\syswow64\cscript.exe '\\hct431vntgta901\test scripts\machine queries\queryTest.vbs'", 1, True)
    If errorCode <> 0 Then
        MsgBox "Error was recieved"
    End If
End Function

每次我尝试运行脚本时都会收到错误,我看不到错误是什么,它只是无法运行脚本。

我已经尝试过,如果我在 CMD 中运行以下命令,它会运行脚本就好了:

C:\Windows\syswow64\cscript.exe "\\hct431vntgta901\test scripts\machine queries\queryTest.vbs"

【问题讨论】:

    标签: vba vbscript


    【解决方案1】:
    wsh.Run("C:\Windows\syswow64\cscript.exe ""\\hct431v ... es\queryTest.vbs""", 1, True)
                                             ^   use escaped double quotes   ^
    

    由于您在命令行中使用了双引号并且它们有效,因此请保留它们。但是要在字符串中放置双引号,您需要对它们进行转义。

    【讨论】:

    • 非常感谢,我不知道为什么我没有想到单引号也可以这样工作。
    猜你喜欢
    • 2013-07-12
    • 2018-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-12
    • 2014-07-25
    • 2015-04-21
    • 2020-10-09
    相关资源
    最近更新 更多