![]() |
|
#5
|
||||
|
||||
|
Try:
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 |
| Convert raw field codes to plain text and back again | ugcheleuce | Word VBA | 3 | 02-14-2017 05:03 AM |
Macro Needed To Convert Text in Word to Plain Text and Back to Word
|
rsrasc | Word VBA | 5 | 12-18-2015 07:13 AM |
Convert image-text hybrids into plain text
|
morlack | Excel | 4 | 12-03-2014 05:29 PM |
How to convert endnotes in a text doc to Word endnotes?
|
Dickison | Word VBA | 4 | 10-06-2012 09:11 PM |
| My plain text post got converted to rich text in a reply, how to convert it back? | david.karr | Outlook | 0 | 01-05-2012 09:46 AM |