![]() |
|
|
|
#1
|
||||
|
||||
|
I think the code got tripped up with the multiple cross-references to the same endnotes. Try:
Code:
Sub Test()
Application.ScreenUpdating = False
Dim Fld As Field, EndNtRng As Range, FldRng As Range, i As Long, j As Long, Rng As Range, RngFld As Field
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
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
Set Rng = FldRng
Rng.End = ActiveDocument.Range.End
If i <> j Then
For Each RngFld In Rng.Fields
If RngFld.Type = wdFieldNoteRef Then
If RngFld.Result = i Then
Set FldRng = RngFld.Code
While FldRng.Fields.Count = 0
FldRng.End = FldRng.End + 1
Wend
FldRng.Fields(1).Delete
FldRng.InsertCrossReference ReferenceType:="Endnote", ReferenceKind:= _
wdEndnoteNumberFormatted, ReferenceItem:=j, InsertAsHyperlink:=True
End If
End If
Next
End If
End If
.Fields.Update
End If
Next
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#2
|
||||
|
||||
|
Thank you for your code Macropod. In my sample document, it worked perfectly except for the ordering like you had said. However, in the actual document it didn't work and would throw a run-time error 13, type mismatch at the line ' i = Fld.Result ', hovering over it reveals the field is "Error! Bookmark not defined". I created another sample document that causes the same error as the actual document. I have experimented with this and cannot cause the links not to break as they are. I thought it should be a matter of doing a select all and update all fields but I have not found where in the code to put that so it works.
Thank you for your help and continued help on this. The actual document I was working on is out of my hands again (I had to do the fixes to it manually), but am certain it will or another like it will come to me soon. |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Separating endnotes from text
|
kenglade | Word | 22 | 09-14-2012 04:10 PM |
Copying endnotes
|
kenglade | Word | 4 | 12-03-2011 01:26 PM |
| Index entries in endnotes | perhj | Word | 0 | 06-19-2011 09:28 AM |
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 |