PatternNut
asked on
How can I automatically close a word dialog box?
Hi Experts,
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.Fi leSystemOb ject")
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
Err.Clear
WasOpen = False
Set d = Documents.Open(fil.Path)
Else
WasOpen = True
End If
d.Activate
Set doctesting = Application.ActiveDocument
If doctesting.ProtectionType = wdNoProtection Then
Load UserForm
UserForm.Show
Call UserForm.StartButton_Click
etc
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.
Cheers,
PatternNut
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.Fi
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
Err.Clear
WasOpen = False
Set d = Documents.Open(fil.Path)
Else
WasOpen = True
End If
d.Activate
Set doctesting = Application.ActiveDocument
If doctesting.ProtectionType = wdNoProtection Then
Load UserForm
UserForm.Show
Call UserForm.StartButton_Click
etc
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.
Cheers,
PatternNut
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Nice one Graham, this worked the charm.
Thank you,
PatternNut
Thank you,
PatternNut
http://www.autoitscript.com/forum/lofiversion/index.php?t27740.html