简体   繁体   English

从 Outlook 宏运行本地 vbscript

[英]Run local vbscript from Outlook macro

I would like to have a macro in Outlook 2010 that will run a vbscript on my local drive.我想在 Outlook 2010 中有一个宏,它将在我的本地驱动器上运行 vbscript。 Here's what I've tried.这是我尝试过的。

Sub RUNvbscript()
Shell "Explorer.exe ""C:\rest of path""", 1
End Sub

That did not work, any suggestions?那没有用,有什么建议吗?

You have a few options here: Shell() , the ShellExecute() API function, scripting host's WShell.Run() , etc. If you need to wait for your script to complete, however, WShell.Run() has a synchronous option, which makes it nice.您在这里有几个选项: Shell()ShellExecute() API 函数、脚本主机的WShell.Run()等。但是,如果您需要等待脚本完成, WShell.Run()有一个同步选项,这让它很好。

strPath = "c:\folder\myscript.vbs"
Set objShell = CreateObject("WScript.Shell")

' Run synchronously...
objShell.Run Chr(34) & strPath & Chr(34), 1, True

' Or, run asynchronously...
objShell.Run Chr(34) & strPath & Chr(34), 1, False

With the others, you'd need to use WaitForSingleObject or some other polling mechanism to determine when the script completes.对于其他人,您需要使用WaitForSingleObject或其他一些轮询机制来确定脚本何时完成。

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

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