I'm writing script that will loop through all macro-enabled Word documents in a folder and run a macro from the command line.
My macro counts pages and if the count is exactly 1, sends the document to the printer.
Because I'll be doing a lot of documents (sometimes up to 200 at a time) I'd like to let it run through and exit with a non-zero code so I can catch those events and report them back to the user.
But Application.Quit
doesn't provide a way to specify an exit code. Is there another way to for the document to exit in such a way that my script can know about it?
EDIT: Code as requested. Replace /path/to stuff with actual paths.
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
}
}