Thread: [Solved] Updating Cross refs
View Single Post
 
Old 11-09-2018, 07:26 AM
Charles Kenyon Charles Kenyon is offline Windows 10 Office 2016
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,530
Charles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant futureCharles Kenyon has a brilliant future
Default

Otherwise, the following macro will update all cross-references in a document, but may be overkill.

Code:
Sub UpdateAllRef()
'   Update all Ref fields in a document, even if in headers/footers or textboxes
    ' https://gregmaxey.com/word_tip_pages/word_fields.html
    ' November 6, 2018 Charles Kenyon
    Dim rngStory As Word.range
    Dim lngValidate As Long ' do not know purpose of this - CK
    Dim oShp As Shape
'    Dim oTOC As TableOfContents, oToa As TableOfAuthorities, oTof As TableOfFigures
    Dim oStory As range
    Dim oField As Field

    lngValidate = ActiveDocument.Sections(1).Headers(1).range.StoryType ' do not know purpose of this
    For Each rngStory In ActiveDocument.StoryRanges
      'Iterate through all linked stories
        For Each oField In oStory.Fields
            If oField.Type = wdFieldRef Then oField.Update
        Next oField
      Do
        On Error Resume Next
        For Each oField In rngStory.Fields
            If oField.Type = wdFieldRef Then oField.Update
        Next oField
            
'        rngStory.Fields.Update
        Select Case rngStory.StoryType
          Case 6, 7, 8, 9, 10, 11
            If rngStory.ShapeRange.Count > 0 Then
              For Each oShp In rngStory.ShapeRange
                If oShp.TextFrame.HasText Then
                    For Each oField In oShp.TextFrame.Fields
                        If oField.Type = wdFieldRef Then oField.Update
                    Next oField
'                   oShp.TextFrame.TextRange.Fields.Update
                End If
              Next
            End If
          Case Else
            'Do Nothing
        End Select
        On Error GoTo 0
        'Get next linked story (if any)
        Set rngStory = rngStory.NextStoryRange
      Loop Until rngStory Is Nothing
'      'Special Cases
'      For Each oTOC In ActiveDocument.TablesOfContents
'        oTOC.Update
'      Next oTOC
'      For Each oToa In ActiveDocument.TablesOfAuthorities
'        oToa.Update
'      Next
'      For Each oTof In ActiveDocument.TablesOfFigures
'        oTof.Update
'      Next
    Next
    '
    Set oStory = Nothing
    Set oField = Nothing
    Set rngStory = Nothing
    Set oShp = Nothing
'    Set oTOC = Nothing
'    Set oToa = Nothing
'    Set oTof = Nothing
End Sub
Reply With Quote