Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #9  
Old 08-15-2012, 04:50 PM
macropod's Avatar
macropod macropod is offline Pasting endnotes and X-Refs into another document Windows 7 64bit Pasting endnotes and X-Refs into another document Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,343
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

OK, try it this way. The new code should also be more efficient than the old, plus (unlike the old) it'll process cross-references in footnotes, endnotes, textboxes, etc.
Code:
Sub Test()
Application.ScreenUpdating = False
Dim Fld As Field, EndNtRng As Range, FldRng As Range, i As Long, j As Long
Dim Rng As Range, StrOld As String, StrNew As String
With ActiveDocument
  For Each Fld In .Fields
    If Fld.Type = wdFieldNoteRef Then
      Set FldRng = Fld.Code
      i = Fld.Result
      While FldRng.Fields.Count = 0
        FldRng.End = FldRng.End + 1
      Wend
      Set EndNtRng = .Endnotes(i).Reference
      If EndNtRng.End > FldRng.End Then
        StrOld = FldRng.Fields(1).Code.Text
        FldRng.Fields(1).Delete
        EndNtRng.Cut
        FldRng.Paste
        FldRng.Style = "EndNote Reference"
        j = FldRng.Endnotes(1).Index
        EndNtRng.InsertCrossReference ReferenceType:="Endnote", ReferenceKind:= _
          wdEndnoteNumberFormatted, ReferenceItem:=j, InsertAsHyperlink:=True
        If FldRng.Characters.First = " " Then FldRng.Characters.First = vbNullString
        StrNew = EndNtRng.Words.First.Fields(1).Code.Text
        ActiveWindow.View.ShowFieldCodes = True
        For Each Rng In .StoryRanges
          With Rng.Find
            .ClearFormatting
            .Replacement.ClearFormatting
            .Text = StrOld
            .Replacement.Text = StrNew
            .Forward = True
            .Wrap = wdFindContinue
            .Format = False
            .MatchCase = True
            .MatchWholeWord = True
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
            .Execute Replace:=wdReplaceAll
          End With
          Rng.Fields.Update
        Next
        ActiveWindow.View.ShowFieldCodes = False
      End If
    End If
  Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Pasting endnotes and X-Refs into another document Separating endnotes from text kenglade Word 22 09-14-2012 04:10 PM
Pasting endnotes and X-Refs into another document Copying endnotes kenglade Word 4 12-03-2011 01:26 PM
Index entries in endnotes perhj Word 0 06-19-2011 09:28 AM
Pasting endnotes and X-Refs into another document Mass Update of Cross-Refs MS2010 judicial85 Word 1 03-08-2011 10:33 PM
Problems with pasting into another document OneDayJD Word 0 04-25-2010 07:51 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 12:27 PM.


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