Suppress word dialog - Fields.Update

D

Daniel W

Hello all
Have used a macro that updates fields in the header when the document is
opened.
Now I want to expand so it updates fields in whole document.
Code works but it displays a dialog that the user has to click Yes to.
Message in dialog: Word cannot undo this action. Do you want to continue?
Is there any way to suppress this message or maybe use SendKeys?

Code:
Sub AutoOpen()
ActiveWindow.Caption = ActiveDocument.FullName
Dim oStory As Range
For Each oStory In ActiveDocument.StoryRanges
' If oStory.StoryType = wdPrimaryHeaderStory Or oStory.StoryType =
wdFirstPageHeaderStory Then
oStory.Fields.Update
' End If
Next oStory
Set oStory = Nothing
End Sub

Thanks
Daniel
 
M

macropod

Hi Daniel,

That message has nothing to do with .Fields.Update as such, but is probably a reflection of the document already containing
extensive unsaved editing which, once the fields are updated, you'll be unable to undo. To suppressthe message, you could try:
Alerts = Application.DisplayAlerts
Application.DisplayAlerts = wdAlertsNone
..Fields.Update
Application.DisplayAlerts = Alerts
This temporarily turns off the alerts display, then restores them to the previous setting once the fields have been updated.
 
D

Daniel W

Hi macropod
Added the extra code as you suggested and that did it!
Worked like a charm.

Big thanks for helping out
 
Z

Ziv Bek

Hi,
I used the same code:
Application.DisplayAlerts = wdAlertsNone

But after loading a "bad" document, I still get warnings such as:
- The document 'temp.doc' caused a serious error the last time it was opened. Would you like to continue opening it?

- Word failed to start correctly last time. Starting Word in safe mode will help you correct ....

How can I suppress all messages no matter what?

I need this for a command-line printing queue. I can't have one bad document to stop the rest of the queue.

Thanks, Ziv
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top