Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-09-2018, 07:26 AM
Charles Kenyon Charles Kenyon is offline Updating Cross refs Windows 10 Updating Cross refs Office 2016
Moderator
 
Join Date: Mar 2012
Location: Sun Prairie, Wisconsin
Posts: 9,583
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
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Updating Cross refs cross-refs: navigate from target back to source eNGiNe Word 1 03-03-2015 12:51 PM
Updating Cross refs Help with set up of automatically updating cross reference. lukebrown Word VBA 5 09-11-2013 09:38 AM
Updating Cross refs Cross references not updating correctly CLWriter Word 4 04-03-2012 07:23 AM
Updating Cross refs cross-referencing - lock/unlock updating minszki Word 1 03-11-2012 11:28 AM
Updating Cross refs Mass Update of Cross-Refs MS2010 judicial85 Word 1 03-08-2011 10:33 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:45 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft