Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 04-22-2014, 10:40 AM
Cosmo Cosmo is offline Questions about EndNotes Windows Vista Questions about EndNotes Office 2007
Competent Performer
Questions about EndNotes
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 04-22-2014, 11:17 PM
macropod's Avatar
macropod macropod is offline Questions about EndNotes Windows 7 32bit Questions about EndNotes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

Quote:
Originally Posted by Cosmo View Post
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.
Word has no native facility for that. The simplest way around it is to not use endnote cross-references. Instead, insert the entire endnote at each location.

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]
Reply With Quote
  #3  
Old 04-23-2014, 05:10 AM
Cosmo Cosmo is offline Questions about EndNotes Windows Vista Questions about EndNotes Office 2007
Competent Performer
Questions about EndNotes
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

Quote:
Originally Posted by macropod View Post
Word has no native facility for that. The simplest way around it is to not use endnote cross-references. Instead, insert the entire endnote at each location.
Unfortunately this is not possible, as the reference list is required by the client to be at the end. Plus, the list of references would take up most of the page in some cases.
Quote:
Originally Posted by macropod View Post
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.
I have thought of that as a possible solution. Since the process will run from a VBA userform, I have a few options available. I have created a function which will recreate the EndNote at the location of the first cross-reference, and that seems to be working well, but I haven't yet gotten the part working which will relink or recreate cross-references to the new EndNote when there are more than a single cross-reference. I have been debating switching to all cross-references, although the benefit of using EndNotes is that it should reorder and renumber automatically.

Thanks for the input.
Reply With Quote
  #4  
Old 04-23-2014, 02:35 PM
Cosmo Cosmo is offline Questions about EndNotes Windows Vista Questions about EndNotes Office 2007
Competent Performer
Questions about EndNotes
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

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
When I run this on one of the bookmarks I need to delete, 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; 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.
Reply With Quote
  #5  
Old 04-23-2014, 03:04 PM
Cosmo Cosmo is offline Questions about EndNotes Windows Vista Questions about EndNotes Office 2007
Competent Performer
Questions about EndNotes
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

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.
Reply With Quote
  #6  
Old 04-23-2014, 03:46 PM
macropod's Avatar
macropod macropod is offline Questions about EndNotes Windows 7 32bit Questions about EndNotes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

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
Note: Although you've only mentioned endnotes, the code is written to process footnotes as well. If you only have one or the other, the difference in execution time is negligible.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #7  
Old 04-24-2014, 06:27 AM
Cosmo Cosmo is offline Questions about EndNotes Windows Vista Questions about EndNotes Office 2007
Competent Performer
Questions about EndNotes
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

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:
First bookmark text 1
Second Bookmark text to be deleted 2
Third bookmark text 3
Cross Reference to second bookmark 2. Cross reference to third bookmark 3.
Fourth bookmark text 4
____________
1 Endnote text 1
2 Endnote text 2
3 Endnote text 3
4 Endnote text 4
When deleting the second bookmark, should result in the following
Quote:
First bookmark text 1
Third bookmark text 2
Cross Reference to second bookmark 3. Cross reference to third bookmark 2.
Fourth bookmark text 4
____________
1 Endnote text 1
2 Endnote text 3
3 Endnote text 2
4 Endnote text 4
I haven't had a chance to really dissect your code just yet (and probably won't have time until tomorrow), but if I do understand what you are saying, and I put all endnotes at the end of the document and only use cross-references to those endNotes, I can't tell if this situation is handled.

Again, thanks for all of your help.
Reply With Quote
  #8  
Old 04-24-2014, 03:03 PM
macropod's Avatar
macropod macropod is offline Questions about EndNotes Windows 7 32bit Questions about EndNotes Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,962
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

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.
Attached Files
File Type: doc EndNotes.doc (60.5 KB, 10 views)
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #9  
Old 04-25-2014, 12:35 PM
Cosmo Cosmo is offline Questions about EndNotes Windows Vista Questions about EndNotes Office 2007
Competent Performer
Questions about EndNotes
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default

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!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to index words in endnotes ClaireB Word 1 11-11-2013 06:05 PM
Questions about EndNotes How to convert endnotes in a text doc to Word endnotes? Dickison Word VBA 4 10-06-2012 09:11 PM
Questions about EndNotes Separating endnotes from text kenglade Word 22 09-14-2012 04:10 PM
Questions about EndNotes Endnotes within Footnotes? elias Word 12 09-04-2012 04:12 PM
Questions about EndNotes Copying endnotes kenglade Word 4 12-03-2011 01:26 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:45 PM.


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