Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带参数的vba WScript.Shell run.exe文件_Vba_Ms Word_Wsh - Fatal编程技术网

带参数的vba WScript.Shell run.exe文件

带参数的vba WScript.Shell run.exe文件,vba,ms-word,wsh,Vba,Ms Word,Wsh,我正在运行Word 2013中的VBA宏。我正在尝试运行一个需要文件名的参数/参数的可执行文件。例如,c:\myfilefilter.exe filetobefilted.htm 我想使用Shell Run,因为我希望VBA代码在恢复VBA代码之前等待可执行文件运行完毕。下面代码的最后三行是我尝试过的一些不起作用的语法的示例。我认为问题在于可执行程序和它过滤的文件之间的空间。有人知道正确的语法或等待可执行程序完成的方法吗。如果您需要更多信息,请询问 将wsh作为对象进行调暗 设置wsh=VBA.

我正在运行Word 2013中的VBA宏。我正在尝试运行一个需要文件名的参数/参数的可执行文件。例如,
c:\myfilefilter.exe filetobefilted.htm

我想使用
Shell Run
,因为我希望VBA代码在恢复VBA代码之前等待可执行文件运行完毕。下面代码的最后三行是我尝试过的一些不起作用的语法的示例。我认为问题在于可执行程序和它过滤的文件之间的空间。有人知道正确的语法或等待可执行程序完成的方法吗。如果您需要更多信息,请询问

将wsh作为对象进行调暗
设置wsh=VBA.CreateObject(“WScript.Shell”)
Dim waitOnReturn为布尔值:waitOnReturn=True
将WindowsStyle设置为整数:WindowsStyle=1
将错误代码设置为整数
Dim strProgramName作为字符串
将strMyFile设置为字符串
调用Shell(“”&strProgramName&“”&strMyFile&“”,vbNormalFocus,waitOnReturn“”)
wsh.Run(strProgramName&&fileToFilterB&&vbNormalFocus,waitOnReturn)
wsh.Run“Chr(34)strprogrammenamechr(34)strMyFile”,waitOnReturn

下面的代码可以工作。strCMD之后的第一个数字是一个布尔参数:1显示dos框,0隐藏dos框;第二个数字类似:1在继续执行VBA代码之前等待程序完成,0不等待

strCMD=sMyProgram+“”+sMyFile 将wsh设置为对象 设置wsh=VBA.CreateObject(“WScript.Shell”) 运行strCMD,1,1 这适合我(来自MsAccess 2013 VBA)


你可以试试这个。对我有用

Const BatchFileName = "P:\Export.bat"
将wsh设置为对象

Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1

wsh.Run BatchFileName, windowStyle, waitOnReturn

Kill BatchFileName

我不知道答案,也没有一个好的测试方法,但是在最后一行中,你应该删除所有的引号,并将Chr(34)和你的变量用符号连接起来。我想你在某处定义了所有这些变量?
Set wsh = VBA.CreateObject("WScript.Shell")
Dim waitOnReturn As Boolean: waitOnReturn = True
Dim windowStyle As Integer: windowStyle = 1

wsh.Run BatchFileName, windowStyle, waitOnReturn

Kill BatchFileName