I'm testing a Word add-in with a script that runs it for lots and lots of documents. It does it like this:
Dim fso As Object, fld As Object, fil As Object
Dim WasOpen As Boolean
Dim d As Document
Set fso = CreateObject("Scripting.FileSystemObject")
Set fld = fso.GetFolder("E:\My Documents\")
For Each fil In fld.Files
If UCase(Right(fil.Name, 4)) = ".DOC" Then
On Error Resume Next
Set d = Documents(fil.Name)
If Err <> 0 Then
WasOpen = False
Set d = Documents.Open(fil.Path)
WasOpen = True
Set doctesting = Application.ActiveDocument
If doctesting.ProtectionType = wdNoProtection Then
However, sometimes the script is interrupted by a Word dialog that comes up before the script reaches reaches call. 'startbutton_click. Specifically, two dialogs sometimes get in the way:
- If the document is password protected then there is a dialog to enter the password or click 'read only'
- A dialog box that says "Problem During Load" - Missing file: etc. And you need to click 'ok'
Neither comes up very often - but when they do, the whole script is interrupted... so I can lose hours of testing time before I find out. Is there any way to automatically answer 'read only' if the password protection one comes up or 'ok' if the problem during load comes up?
Thanks in advance for any advice.