How to detect Word.Application.SaveAs timeouts?

Viewed 63

I have a VBS script that converts a bunch of word (doc, dox, and docm) and powerpoint (pptx) files into PDFs, via Word and PowerPoint application objects and argument SaveAs.

That works fine, but for reasons unknown the processing fails for some Word files (guess: the files were created with another office version, or have some corruption). SaveAs runs indefinitely, with Word running using 100% of a CPU core, until I kill it manually.

After the SaveAs operation has ran for a programmed amount of time (say 5 minutes), I'd like to:

  1. Abort the current SaveAs operation.
  2. Raise an error.

I could then dispatch an error message via mail, then proceed to the next file (by specifying On Error Resume Next).

This code excerpt shows how I convert Word files to PDF in the script:

Dim  oWord, Pres
Set oWord   = CreateObject("Word.Application")
Set Pres    = oWord.Documents.Open("/path/to/file.docm", , , msoFalse)
Pres.SaveAs "/path/to/file.pdf", 17, True 'runs forever on certain files
Pres.Close 0

How can I abort the current SaveAs operation after a specified delay has elapsed?

0 Answers
Related