#1
|
|||
|
|||
Separating endnotes from text
I'm using Word 2011 with Lion. I want to separate the endnotes from the text of the chapter and put them in a separate document. Word won't let me do a Cmd-X on the endnotes. I have a macro which will do this, but when I do it screws up the chapter text. Where I have a "1" endnote it becomes "a1a" and so forth. I guess i could do a search and replace for the "a1a" but then it would become simply a "1" and not an endnote.
I can't just copy the chapter text with CMD-X because it carries the endnotes with it when I paste. I incorrectly assumed that this would be possible Word, after all its versions, but I guess not. |
#2
|
||||
|
||||
You will have to convert the endnotes to text before you can copy them into a separate document. Doug Robbins has suggested the following macro in the old Word newsgroups (I don't know if it works for MacWord, though):
Code:
Sub ConvertEndNotes() Dim aendnote As Endnote For Each aendnote In ActiveDocument.Endnotes ActiveDocument.Range.InsertAfter vbCr & _ aendnote.Index & vbTab & _ aendnote.Range aendnote.Reference.InsertBefore "a" & aendnote.Index & "a" Next aendnote For Each aendnote In ActiveDocument.Endnotes aendnote.Reference.Delete Next aendnote Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting With Selection.Find.Replacement.Font .Superscript = True End With With Selection.Find .Text = "(a)([0-9]{1,})(a)" .Replacement.Text = "\2" .Forward = True .Wrap = wdFindContinue .Format = True .MatchWildcards = True End With Selection.Find.Execute Replace:=wdReplaceAll End Sub
__________________
Stefan Blom Microsoft Word MVP Microsoft 365 apps for business Windows 11 Professional Last edited by macropod; 01-26-2012 at 02:50 PM. Reason: Added code tags |
#3
|
|||
|
|||
Quote:
That macro does indeed work, but there is a problem. In the document where I have a superscript "1" at the end of the document there also is a smaller font "1." But when I run the macro, I get the following: 1 (normal size) indent Now is the time etc At the same time, it changes the superscript "1" in the document to "a1a" Like other things in Word for Mac, I guess it just ain't doable. But I appreciate your time. Ken Last edited by macropod; 01-26-2012 at 02:51 PM. Reason: Deleted quote of un-tagged code |
#4
|
||||
|
||||
It might be possible to modify the macro so that it does apply superscript formatting, but I wouldn't be the right person to make that modification, I'm afraid.
__________________
Stefan Blom Microsoft Word MVP Microsoft 365 apps for business Windows 11 Professional |
#5
|
|||
|
|||
Many thanks, Stefan. I really appreciate your help on this. Unfortunately, I'm not skilled enough to make the changes. I'll just devise some sort of workaround. Have decided, though, when I start another project like this I'm going to switch to Scrivener -- MS is absolutely useless in this situation -- nothing on line and nothing I can find in a web search for books on Word 2011. The one that keeps popping up by Chris Grover is remarkably deficient. If I were the publisher I'd be embarrassed.
|
#6
|
||||
|
||||
Hi Ken,
On a PC, if you access a footnote or endnote range and press Ctrl-A, that selectes all the footnotes or endnotes in the document. You can then use the normal copy/paste commands to replicate them in a new document. The only 'issues' with this are that: a) you can't delete footnotes or endnotes from the original document this way; and b) the paste footnotes or endnotes all end up numbered 1 in the new document. A macro can easily enough address both issues: Code:
Sub ExtractEndNotes() Application.ScreenUpdating = False Dim Rng As Range, i As Long, Doc As Document With ActiveDocument If .Endnotes.Count = 0 Then Exit Sub For i = 1 To .Endnotes.Count Set Rng = .Endnotes(i).Reference With Rng .Collapse wdCollapseEnd .Text = i .Style = "Endnote Reference" End With Next .StoryRanges(wdEndnotesStory).Copy For i = .Endnotes.Count To 1 Step -1 .Endnotes(i).Delete Next End With Set Doc = Documents.Add With Doc.Range .Paste With .Find .ClearFormatting .Text = "" .Style = "Endnote Reference" .Replacement.Text = "" .Forward = True .Wrap = wdFindStop .Format = True .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Execute End With Do While .Find.Found i = i + 1 .Text = i .Collapse wdCollapseEnd .Find.Execute Loop .Characters.Last.Delete End With Set Rng = Nothing: Set Doc = Nothing Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#7
|
|||
|
|||
Hi, Paul
Many thanks for your note. Sad to say, it isn't working on my Mac. Here's what's happening. Say this is my original: Now is the time[i] [i] For all good men Using a macro provided by Stefan, I can change the endnote to look like this: Now is the time a1a 1 For all good men I can now Cmd-X on the enddnote and move it to a separate document. But that leaves me with this in the original: Now is the time a1a a1a has replaced the superscript 1. I would ahve to go back through the original and change every aXa to a superscript. I have no idea how to do this and I don't think it would be productive to try. For some reason MS has decided to make it impossible to separate the endnotes from the original. Seems to me they never gave it a second thought. That's what I call half-ass work. Saludos, Ken For |
#8
|
||||
|
||||
Hi Ken,
You say that the macro I provided isn't working, but you don't provide any details. Instead, you tell me what Doug Robbins' code (supplied by Stefan) does - which I was already aware of. In what way isn't my macro working? As for: Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] Last edited by macropod; 01-27-2012 at 03:53 PM. Reason: Correct attribution of Doug Robbins' code (supplied by Stefan) |
#9
|
|||
|
|||
Sorry, I should have been more explicit. When I try it I get: "Run-time error 4605, This method of property is not available because the object spans a frame or note boundary." And then it tries to debug.
Re MS, Word bills itself as a tool for writers. I'm writing a book with about 30 chapters. Publishers don't like to publish with the end notes at the end of each chapter. What they do is move them from the end of each chapter to a document in the back of the book usually called "Chapter Notes" or just "notes." I can do this as far as the endnotes are concerned but the original document does not have the superscript number at the desired location. Rather it has "aXa" and I don't know of a way to change that back to the old superscript. If I could just remove the end notes that might help but Word won't let me do that. I'm a writer, not a computer whiz. There may be some way but I just don't understand and I can't find anything on the web to help. It seems very shortsighted on MS to allow the creation of endnotes without a way to manipulate them. Do you know how? Saludos, Ken |
#10
|
||||
|
||||
Hi Ken,
Re: Quote:
Re: Quote:
Now is the time[i] [i] For all good men and that it was Doug Robbins' code (supplied by Stefan) that generated the "aXa" output. That code should only have left you with the "X" - superscripted where the original endnote references appeared and as plain text at the end of the document. A serious limitation (IMHO) is that it also kills any formatting you had in your endnotes - my code retains it. As for Word's functionality, it already has built into it the ability to place footnotes at the bottom of each page, and endnotes at either the end of each Section (chapter), or at the end of the document. I have never before encountered a requirement for them to be moved to a separate document.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] Last edited by macropod; 01-27-2012 at 07:03 PM. |
#11
|
|||
|
|||
Macropod
I very much appreciate the time you're putting into this and I feel guilty about it. In any case, I've attached a sample, two as a matter of fact. sample.doc is the original. When I highlight the endnotes and run your macro I get the run time error but nothing is highlighted. sample_02 is the same material after running Stefan's macro on the highlighted material. Notice the "aXa"s in the copy. I can go through them, delete the "a" s on each side of the number, then superscript the number but that would take forever. BTW, I'm running Word 2011 on an Intel Mac. To highlight the footnotes I use CMD-a rather than CTRL-a. Maybe the Mac thing is screwing it up. Saludos, Ken |
#12
|
||||
|
||||
On a Windows system, running the macro with your example document certainly works as expected. That suggests the problem is MacWord-specific.
__________________
Stefan Blom Microsoft Word MVP Microsoft 365 apps for business Windows 11 Professional |
#13
|
||||
|
||||
Hi Ken,
With the sample.doc you posted, does the Run-time error 4605 occur on that when you use the code I posted? If so, how much of the processing has been done at that stage (it might be easier to see if you uncomment the line 'Application.ScreenUpdating = False' before running the code)? Both Doug's code (supplied by Stefan) and mine run to completion on a PC, so (assuming the answer to the first question above is yes) the errors seem to be either Mac-specific or specific to just your system. Maybe there's a fault with the Word installation on your system - that seems possible since neither the Find/Replace routine in Doug's code nor some aspect of my code work correctly. Be that as it may, you should be able to process the 'aXa' content left over from Doug's code with a wildcard Find/Replace (that's what the macro tries to do), where: Find = a([0-9]{1,})a Replace = \1 and the replacement font is set to superscript. Finally, here's another two macros to try. The first is a modified version of Doug's code. It should retain both your endnote formatting and superscript the numbers. The second is a quite different macro I've written that will also preserve non-numeric endnote references (you previous reference to [i] suggested you were actually using roman numerals). Code:
Sub ConvertEndNotes() Application.ScreenUpdating = False Dim aendnote As Endnote, Rng As Range With ActiveDocument .Range.InsertAfter vbCr For Each aendnote In .Endnotes Set Rng = .Range.Characters.Last Rng.Style = "Endnote Text" With aendnote .Range.Copy Rng.InsertAfter vbCr & "[" & .Index & "] " Rng.Collapse wdCollapseEnd Rng.Paste .Reference.InsertBefore "[" & .Index & "]" End With Next aendnote For Each aendnote In .Endnotes aendnote.Reference.Delete Next aendnote With .Content.Find .ClearFormatting .Replacement.ClearFormatting .Text = "\[([0-9]{1,})\]" .Replacement.Style = "Endnote Reference" .Replacement.Text = "\1" .Forward = True .Wrap = wdFindContinue .Format = True .MatchWildcards = True .Execute Replace:=wdReplaceAll End With End With Set Rng = Nothing Application.ScreenUpdating = True End Sub Code:
Sub UnLinkNotes() Application.ScreenUpdating = False Dim nRng As Range, eNote As Endnote, nRef As String With ActiveDocument For Each eNote In .Endnotes With eNote With .Reference.Characters.First .Collapse wdCollapseStart .InsertCrossReference wdRefTypeEndnote, wdEndnoteNumberFormatted, eNote.Index nRef = .Characters.First.Fields(1).Result .Characters.First.Fields(1).Unlink End With .Range.Cut End With Set nRng = .Range With nRng .InsertAfter vbCr & nRef & " " With .Paragraphs.Last.Range .Style = "Endnote Text" .Words.First.Style = "Endnote Reference" End With .Collapse wdCollapseEnd .Paste End With Next For Each eNote In .Endnotes eNote.Delete Next End With Set nRng = Nothing Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#14
|
|||
|
|||
Curses. But thanks anyway. I have an old PC I never use anymore so once I get past this deadline I'll give it a try.
Saludos, Ken |
#15
|
||||
|
||||
Hi Ken,
FWIW, does the following achieve what you're after? Code:
Sub ExportEndNotes() Application.ScreenUpdating = False Dim Rng As Range, DocSrc As Document, DocTgt As Document, i As Long, StrRef As String Set DocSrc = ActiveDocument With DocSrc 'Unlink endnote/footnote cross-references For i = .Fields.Count To 1 Step -1 If .Fields(i).Type = wdFieldNoteRef Then .Fields(i).Unlink Next 'Process all endnotes For i = 1 To .Endnotes.Count 'First, process the endnote ref in the document body Set Rng = .Endnotes(i).Reference With Rng .Collapse wdCollapseStart 'To get the actual reference text, we need to cross-reference it! .InsertCrossReference wdRefTypeEndnote, wdEndnoteNumberFormatted, i, False, False .End = .End + 1 StrRef = .Text .Fields(1).Unlink End With 'Second, process the endnote ref in the endnote Set Rng = .Endnotes(i).Range.Paragraphs.First.Range.Words.First With Rng If .Characters.Last Like "[ " & vbTab & "]" Then .End = .End - 1 'Overwrite the existing endnote reference .Text = StrRef End With Next 'Give Word a chance to do its housekeeping DoEvents 'Create the output document Set DocTgt = Documents.Add 'Replicate the endnotes in the body of the output document DocTgt.Range.FormattedText = .StoryRanges(wdEndnotesStory).FormattedText 'Delete the endnotes from the source document For i = .Endnotes.Count To 1 Step -1 .Endnotes(i).Delete Next End With Set Rng = Nothing: Set DocTgt = Nothing: Set DocSrc = Nothing Application.ScreenUpdating = True End Sub
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Changing footnotes to endnotes | Sarah | Word | 3 | 04-27-2017 08:55 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 |
how do I change fonts for endnotes of word 2007? | Brent | Word | 5 | 02-01-2011 03:15 PM |
Separating accounts | aka252 | Outlook | 0 | 02-23-2006 07:55 PM |