none
field update RRS feed

  • Question

  • Word 2010 ... I have a 600-page doc with inserted text fields and page ref fields. Before printing I try to update all page ref fields, so I have a macro that says if it's a pageref field then field.update. The vba update takes several minutes each time. However, going to the field and pressing F9 updates the page number immediately. I don't want to update the inserted text fields, only the page ref fields. (While print preview seems to work, and work very quickly, I'm curious why vba is so slow). Thanks for any light you can cast on this question.

    Joe Lewis

    • Moved by PWMatherMVP Friday, February 5, 2016 10:13 PM Word query
    Friday, February 5, 2016 3:37 PM

Answers

  • It's not clear from your post what you mean regarding "I don't want to update the inserted text fields". If these are formfields, field updating won't affect them. If they're links to external files, you could obviate the need for VBA by checking Word's 'update fields before printing' option and unchecking the 'update linked data before printing' option. See under File|Options|Display. You could even toggle either or both of those options via VBA. Regardless, you should be able to update the fields in the way Print preview does, via code like:

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


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Monday, February 8, 2016 9:59 AM

  • Hi John,

    Did you mean that it is very slowly that when you update one page ref field instead of all fields?  If I understood correctly, I am failed to reproduce this issue. I made a test for update 1000 page ref fields using code below and it take about 51s:

    Sub updateField() Application.ScreenUpdating = False a = Now For Each aField In ActiveDocument.Fields aField.Select Selection.Fields.Update Next aField

    Application.ScreenUpdating = True c = Now Debug.Print c Debug.Print a End Sub

    And after the testing, update the multiple fields in one selection is faster than update the field individually. You can try to select the range that you want to update and update those fields using code below as you pressing F9 to update manually:

      Selection.Fields.Update
    

    If you still have the problem, would you minding share more detail to help us to understand this issue exactly.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, February 8, 2016 5:02 AM
    Moderator

All replies

  • Joe,

    Sorry but you have posted to a forum that deals exclusively with questions/issues about customizing and programming Microsoft Project, a project management application. I suggest you re-post to a Work forum such as the following:

    https://social.msdn.microsoft.com/Forums/office/en-US/home?forum=worddev

    John

    Friday, February 5, 2016 3:44 PM

  • Hi John,

    Did you mean that it is very slowly that when you update one page ref field instead of all fields?  If I understood correctly, I am failed to reproduce this issue. I made a test for update 1000 page ref fields using code below and it take about 51s:

    Sub updateField() Application.ScreenUpdating = False a = Now For Each aField In ActiveDocument.Fields aField.Select Selection.Fields.Update Next aField

    Application.ScreenUpdating = True c = Now Debug.Print c Debug.Print a End Sub

    And after the testing, update the multiple fields in one selection is faster than update the field individually. You can try to select the range that you want to update and update those fields using code below as you pressing F9 to update manually:

      Selection.Fields.Update
    

    If you still have the problem, would you minding share more detail to help us to understand this issue exactly.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Monday, February 8, 2016 5:02 AM
    Moderator
  • It's not clear from your post what you mean regarding "I don't want to update the inserted text fields". If these are formfields, field updating won't affect them. If they're links to external files, you could obviate the need for VBA by checking Word's 'update fields before printing' option and unchecking the 'update linked data before printing' option. See under File|Options|Display. You could even toggle either or both of those options via VBA. Regardless, you should be able to update the fields in the way Print preview does, via code like:

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


    Cheers
    Paul Edstein
    [MS MVP - Word]

    Monday, February 8, 2016 9:59 AM