title: Updating page numbers in VBA
body: <p>I have a Word document that uses many different fields. I wrote a macro that updates all the <strong><code>sequence</code></strong>, <strong><code>reference</code></strong>, page, and <strong><code>numpages</code></strong> fields in the document. </p>
  
  <p>Updating text fields reverts them back to their default text so I don't want those updated. </p>
  
  <p>This macro worked perfectly in Word 2007 but I recently updated to Word 2013 and it doesn't work properly anymore. </p>
  
  <p>All page and <strong><code>numpages</code></strong> fields are set to 1 when this macro runs. Yet when I update them manually, they update correctly. </p>
  
  <p>Was there a change to how fields are updated in Office 2013? </p>
  
  <p>The macro code is below.</p>
  
  <pre><code>Sub UpdateAllFields()
  UnprotectDocument
  
  'UpdateAllFields Macro
      Dim objDoc As Document
      Dim objFld As Field
  
  'Updates the specified form fields. This can take a while when the document gets large
      Set objDoc = ActiveDocument
      For Each objFld In objDoc.Fields
          If objFld.Type = wdFieldRef Then 'Updates Cross References
              objFld.Update
          If objFld.Type = wdFieldPage Then 'Updates Page Numbers
              objFld.Update
          ElseIf objFld.Type = wdFieldNumPages Then 'Updates Total Page Count
              objFld.Update
          ElseIf objFld.Type = wdFieldSequence Then 'Updates Sequence Fields
              objFld.Update
          End If
      Next objFld
  
  ProtectDocument
  
  End Sub
  </code></pre>