Link to home
Start Free TrialLog in
Avatar of PatternNut
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.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
                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
Avatar of William Elliott
William Elliott
Flag of United States of America image

on error resume next ignore these, but for the specific results you want i utilize a program called 'autoit' you can create and adlib function that hangs out until it sees a specific windows, then runs a function like clicking read only or ok. you should be able to run the autoit from your vb code. or reference the dll to add it directly to vb6

http://www.autoitscript.com/forum/lofiversion/index.php?t27740.html
ASKER CERTIFIED SOLUTION
Avatar of GrahamSkan
GrahamSkan
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PatternNut
PatternNut

ASKER

Nice one Graham, this worked the charm.

Thank you,

PatternNut