vbams-wordfield

Macro to update all fields (including ask fields) without the ask field prompt popping up


Looking for a vba code to update all fields without the prompts that belong to Ask fields, such as Print Preview does. Although, a code to open and close Print Preview is not desired because it brings me back to the top of the document instead of leaving me on the page where I was. I'm talking about this code:

Sub Update()

Application.ScreenUpdating = False
    With ActiveDocument
        .PrintPreview
        .ClosePrintPreview
    End With
    Application.ScreenUpdating = True
End Sub

Is there an alternative way to update all fields but to tell the prompts not to show up? Or is the prompt field of ask field inherent to them, and can't they be disabled during the action?

Thanks in advance for your support

Willem


Solution

  • The code you posted doesn't take you back to the top of the document, per se; it takes you back to the top of the current page. You can force it to bring the current selection back into view by adding:

    ActiveWindow.ScrollIntoView Selection.Range
    

    before exiting. For example:

    Sub UpdateFields()
    Application.ScreenUpdating = False
    With ActiveDocument
      .Fields.Update
      .PrintPreview
      .ClosePrintPreview
    End With
    ActiveWindow.ScrollIntoView Selection.Range
    Application.ScreenUpdating = True
    End Sub
    

    That will still leave you with the ASK & FILLIN field prompts, though. You can deal with both issues using code like:

    Sub UpdateFields()
    Application.ScreenUpdating = False
    Dim Fld As Field
    With ActiveDocument
      For Each Fld In .Fields
        Select Case Fld.Type
          Case wdFieldAsk, wdFieldFillIn: Fld.Locked = True
        End Select
      Next
      .Fields.Update
      .Fields.Locked = False
      .PrintPreview
      .ClosePrintPreview
    End With
    ActiveWindow.ScrollIntoView Selection.Range
    Application.ScreenUpdating = True
    End Sub
    

    Updating ASK & FILLIN fields without the field prompts isn't going to happen.