#1
|
|||
|
|||
Questions about EndNotes
I have a document which has a long list of references to be included at the end of the document (which I have set up as EndNotes). The document will be used as a master template; the user will choose a set of options and based on those choices, the appropriate sections of the document will be either removed or included in the final document
When a section is removed, the corresponding notes are to be removed as well, and this works as I have expected. The unneeded notes are removed, and the existing notes are renumbered to follow their current order. However, several of the references are used in multiple places, and I have not seen any way to do this other than to create the EndNote at the first instance, then create a cross-reference to the EndNote for later uses. The problem is, if the section that includes the original EndNote is removed, but is still used somewhere else via a cross-reference, then the referenced note is still deleted. Is there a way to do this so that a note is only deleted when all references to it are removed? Also, it would have to be renumbered if there are other notes between the first occurrance, and the first cross reference. |
#2
|
||||
|
||||
Quote:
Alternatively, you could store all the endnotes and their references in one place (e.g. at the end of the document), with only cross-references to them elsewhere in the document. Then, when the content deletion is complete, move each endnote to wherever the first cross-reference to it appears and delete any endnotes that aren't cross-referenced.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Quote:
Quote:
Thanks for the input. |
#4
|
|||
|
|||
I have run into a snag in my VBA solution.
I am checking all endNotes in each bookmark before I delete the bookmark, and relinking, which works fine for the first cross-reference, but I have problems if there are multiples. I have tracked it down to an issue with getting the EndNotes in a bookmark. Here's a snippet of code I am using: Code:
Dim noteCount as integer Dim eNote as EndNote noteCount = oBookmark.Range.EndNotes.Count Debug.Print "Bookmark " & oBookmark.name & " has " & CStr(noteCount) & " EndNotes." if (noteCount > 0) Then For Each eNote in oBookmark.Range.Endnotes Debug.Print "EndNote #" & eNote.index Next eNote end if Is this a bug, the fact that oBookmark.Range.EndNotes.Count lists 7, but when I loop through the oBookmark.Range.EndNotes collection, I get 42; or is there an error in my code? If this is a bug, is there something I can do to work around this? I haven't tried it yet, but would it be worthwhile to check eNote.Range.Bookmarks or eNote.Range.BookmarkID to verify that the EndNote belongs to the current bookmark (assuming this will work)? EDIT: I'm getting a '0' for both the BookMarkID & Bookmarks.Count I'm running Word 2007 (which is the same version our client will be using), if that matters. |
#5
|
|||
|
|||
I need to run a function on all EndNotes in a specific bookmark in my document, and I am using the following stripped down code: Code:
Dim noteCount as integerDim eNote as EndNotenoteCount = oBookmark.Range.EndNotes.Count Debug.Print "Bookmark " & oBookmark.name & " has " & CStr(noteCount) & " EndNotes." if (noteCount > 0) Then For Each eNote in oBookmark.Range.Endnotes Debug.Print "EndNote #" & eNote.index Next eNoteend if When I run this on one of the bookmarks in my document, I get the correct NoteCount (e.g. 7), but the loop runs through ALL of the EndNotes in the document (e.g. I get 42 lines of 'EndNote #X') Is this a bug, the fact that oBookmark.Range.EndNotes.Count lists 7, but when I loop through the oBookmark.Range.EndNotes collection, I get 42 EndNotes, or is there an error in my code? If this is a bug, is there something I can do to work around this? I tried to check eNote.Range.Bookmarks and eNote.Range.BookmarkID to verify that the EndNote belongs to the current bookmark, but I'm getting a '0' for both eNote.Range.BookmarkID & eNote.Range.Bookmarks.Count I'm running Word 2007, if that matters. |
#6
|
||||
|
||||
If, as advised in my previous reply, you start off with all of the footnotes & endnotes at the end of the document and all the footnote & endnote references as cross-references to those endnotes, running the following macro after your editing is done will ensure all footnote & endnote references are placed before any applicable cross-references. You will then only need to delete whatever footnote & endnote references are still at the end of the document after running the macro.
Code:
Sub ReorderNotes() Application.ScreenUpdating = False Dim Fld As Field, NtRng As Range, FldRng As Range Dim Rng As Range, StrOld As String, StrNew As String Dim ENtStyle As Long, FNtStyle As Long, i As Long, j As Long With ActiveDocument ENtStyle = .Endnotes.NumberStyle FNtStyle = .Footnotes.NumberStyle .Endnotes.NumberStyle = wdNoteNumberStyleArabic .Footnotes.NumberStyle = wdNoteNumberStyleArabic .Fields.Update 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 NtRng = .Endnotes(i).Reference If NtRng.End > FldRng.End Then StrOld = FldRng.Fields(1).Code.Text FldRng.Fields(1).Delete NtRng.Cut FldRng.Paste FldRng.Style = "EndNote Reference" j = FldRng.Endnotes(1).Index NtRng.InsertCrossReference ReferenceType:="Endnote", ReferenceKind:= _ wdEndnoteNumberFormatted, ReferenceItem:=j, InsertAsHyperlink:=True If FldRng.Characters.First = " " Then FldRng.Characters.First = vbNullString StrNew = NtRng.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 ElseIf Fld.Type = wdFieldFootnoteRef Then Set FldRng = Fld.Code i = Fld.Result While FldRng.Fields.Count = 0 FldRng.End = FldRng.End + 1 Wend Set NtRng = .Footnotes(i).Reference If NtRng.End > FldRng.End Then StrOld = FldRng.Fields(1).Code.Text FldRng.Fields(1).Delete NtRng.Cut FldRng.Paste FldRng.Style = "FootNote Reference" j = FldRng.Endnotes(1).Index NtRng.InsertCrossReference ReferenceType:="Footnote", ReferenceKind:= _ wdFootnoteNumberFormatted, ReferenceItem:=j, InsertAsHyperlink:=True If FldRng.Characters.First = " " Then FldRng.Characters.First = vbNullString StrNew = NtRng.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 .Endnotes.NumberStyle = ENtStyle .Footnotes.NumberStyle = FNtStyle .Fields.Update End With Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Thanks for all of the help, sorry I must have misunderstood your suggestion when I first read it. I will look into the code you provided when I get a chance.
One question: does your code account for the case where an EndNote automatically moves position when a section that contains the first instance is removed, and the second instance occurs after one or more new EndNotes? Example below: Quote:
Quote:
Again, thanks for all of your help. |
#8
|
||||
|
||||
The idea is to start off with a document that has all the endnotes attached to the last paragraph in the document, with nothing else in that paragraph, and everywhere else in the document use endnote cross-references. After doing your edits, the document might then look like the attached. You then simply run the macro (which I've added to the document with a couple of extra lines to delete that last paragraph when its done) and all your endnotes will be re-arranged with numbering re-ordered and with their initial references located in the document ahead of the cross-references to them.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#9
|
|||
|
|||
Thanks again, I had a quick chance to look at the doc you provided (thanks for going over and beyond the call) and it looks to do exactly what I need. I will hopefully have a chance later to incorporate it into my file, and when I have more time, I will try to dissect the code so I can understand what it is doing.
Much appreciation! |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to index words in endnotes | ClaireB | Word | 1 | 11-11-2013 06:05 PM |
How to convert endnotes in a text doc to Word endnotes? | Dickison | Word VBA | 4 | 10-06-2012 09:11 PM |
Separating endnotes from text | kenglade | Word | 22 | 09-14-2012 04:10 PM |
Endnotes within Footnotes? | elias | Word | 12 | 09-04-2012 04:12 PM |
Copying endnotes | kenglade | Word | 4 | 12-03-2011 01:26 PM |