Consulting

Results 1 to 2 of 2

Thread: Turn off calculation during Word Macro?

  1. #1
    www.MrExcel.com VBAX Newbie
    Joined
    Jun 2004
    Posts
    5
    Location

    Turn off calculation during Word Macro?

    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:

    [vba]shp.Range.InsertCaption Label:="Fig.", TitleAutoText:="", _
    Title:="", Position:=wdCaptionPositionBelow[/vba]

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

    Bill

  2. #2
    VBAX Tutor
    Joined
    Mar 2005
    Posts
    268
    Location
    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:
    [vba]ActiveDocument.Fields.Locked = True
    Application.ScreenUpdating = False[/vba]
    at the start, and:
    [vba]ActiveDocument.Fields.Locked = False
    if ActiveDocument.Fields.Update = 0 then
    Msgbox "Updates complete"
    else
    Msgbox "Updates failed to complete."
    end if
    Application.ScreenUpdating=True[/vba]
    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •