我正在编写脚本,它将遍历文件夹中所有启用宏的Word文档并从命令行运行宏。退出Word VBA宏的代码?
我的宏计数页面,如果计数完全是1,则将文档发送到打印机。
因为我会做很多文件(有时一次最多200个)我想让它通过并以非零代码退出,以便我可以捕获这些事件并将其报告回来给用户。
但是Application.Quit
没有提供指定退出码的方法。还有另外一种方式让文档退出,这样我的脚本就可以知道它了吗?
编辑:代码按要求。用实际路径替换/路径/东西。
function bulkPrint() {
// Get folder of files
$files = scandir("/path/to/my/files/");
$output = "";
$exitCode = -1;
// Loop through each file
foreach($files as $file) {
// Not real paths
exec("/path/to/winword.exe /q /x /mMyMacro \"/path/to/my/files/" . $file . "\"", $output, $exitCode);
echo $exitCode; // Always returns 0 because Word exited cleanly
}
}
您可以发布您的代码吗?你如何运行“从命令行宏”?我似乎只是有宏返回状态会更容易。 – Comintern
你想也许是:'子退出() MSGBOX“跳槽” 退出小组 结束小组 ' – Andy
@Andy:这只是退出子,不退出Word,并返回一个非零代码。 – Grayda