从 Excel VBA 调用 .vbs 脚本 [英] Calling a .vbs script from Excel VBA

查看:68
本文介绍了从 Excel VBA 调用 .vbs 脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在需要时从 VBA 代码调用 .vbs 脚本?如果可能的话,你能给我一个如何做到这一点的示例代码吗?

Is it possible to call a .vbs script from a VBA code whenever needed? If possible then can you give me a sample code of how to do so?

推荐答案

运行文件:

Shell "wscript c:\null\a.vbs", vbNormalFocus

如果 VBS 想要使用控制台,请将 wscript 替换为 cscript.

replacing wscript with cscript if the VBS wants to use the console.

或者您可以添加对Microsoft Script Control 并直接与 VBScript 运行时交互以执行 VBS 代码、程序等;

Or you can add a reference to the Microsoft Script Control and interact with the VBScript runtime directly to execute VBS code, procedures etc;

Dim scr As ScriptControl: Set scr = New ScriptControl
scr.Language = "VBScript"
scr.AddCode "sub T: msgbox ""All Hail Cthulhu"": end sub"
scr.Run "T"

这篇关于从 Excel VBA 调用 .vbs 脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆