PDA

View Full Version : Turn off calculation during Word Macro?



MrExcel
04-24-2005, 08:57 PM
Suat provided a macro that loops through all inline images in a document and inserts a caption for each image. I have 1460 images in the document.

At first, the macro was running very fast.

But, after each time through the loop, the Word status bar says that Word is calculating all fields. I am up to 500+ images done and each caption is taking 15-20 seconds. The pause happens immediately after:

shp.Range.InsertCaption Label:="Fig.", TitleAutoText:="", _
Title:="", Position:=wdCaptionPositionBelow

Is there a way to have Word stop calculating until the macro is finished and then to calculate all captions at once?

Bill

BlueCactus
04-24-2005, 11:09 PM
Not too sure. But the Fields collection object has a Locked = True/False property which may prevent updating. It also has an Update function to force updates.

So you might try:
ActiveDocument.Fields.Locked = True
Application.ScreenUpdating = False
at the start, and:
ActiveDocument.Fields.Locked = False
if ActiveDocument.Fields.Update = 0 then
Msgbox "Updates complete"
else
Msgbox "Updates failed to complete."
end if
Application.ScreenUpdating=True
at the end.
Note though that I don't do much with Word VBA, and have not tested this code. Maybe someone else can give you a better reply.