【问题标题】:How to pass the result of VBS to VBA as the variable如何将 VBS 的结果作为变量传递给 VBA
【发布时间】:2022-01-25 17:07:11
【问题描述】:

我想将运行我的 vbs 文件后的结果作为变量传递给 VBA,但是我不知道该怎么做,请您帮忙吗?

我的 vbs 代码:

wscript.echo GetLocale 

'我想传递这个输出 (2033),它将在 VBA 中分配为 myvbsvar。

在 VBA 中,我会将其与 en-us 进行比较,如果 ~= 1057 -> 将调用另一个 VBS 脚本将其更改为 en-gb。我卡在步骤将 VBS 传递给 VBA :(

【问题讨论】:

标签: excel vba


【解决方案1】:

您可以使用 cscript.exe 从 VBA 运行脚本并从中读取输出。见Capture output value from a shell command in VBA

如果您使用的是 Windows,那么这应该可以:

Dim MyOutput As String
MyOutput = CreateObject("WScript.Shell") _
        .Exec("C:\Windows\System32\cmd.exe /c C:\Windows\System32\cscript.exe /NOLOGO ""C:\YourScript.vbs""") _
        .StdOut _
        .ReadAll
Debug.Print MyOutput

如果您想使用 64 位版本的 cscript.execmd.exe,请改用以下路径:

C:\Windows\SysWOW64\cmd.exe
C:\Windows\SysWOW64\cscript.exe

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-14
    相关资源
    最近更新 更多