Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-22-2017, 04:14 PM
SlimYooper SlimYooper is offline Convert endnotes into plain text exactly Windows 10 Convert endnotes into plain text exactly Office 2016
Novice
Convert endnotes into plain text exactly
 
Join Date: Oct 2017
Posts: 4
SlimYooper is on a distinguished road
Default Convert endnotes into plain text exactly

I need to split a large file into two separate files with the main text in one file and all of the endnotes in the other, but without losing the superscript references exactly as they were originally.
I've found a macro that will split endnotes off, with referents, but they start at 1 and go up into the hundreds. I currently have the file use small letters to mark endnotes, and they start over at "a" in every new chapter. How would I get a macro, either to read and reproduce the letter used originally, or detect that it has entered a new chapter/section and start over? (numbers would be okay instead of letters if they'd just start over when they're supposed to).
Reply With Quote
  #2  
Old 10-22-2017, 04:20 PM
SlimYooper SlimYooper is offline Convert endnotes into plain text exactly Windows 10 Convert endnotes into plain text exactly Office 2016
Novice
Convert endnotes into plain text exactly
 
Join Date: Oct 2017
Posts: 4
SlimYooper is on a distinguished road
Default

I probably should have included the code for what I've found

Code:
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
Reply With Quote
  #3  
Old 10-22-2017, 07:48 PM
macropod's Avatar
macropod macropod is offline Convert endnotes into plain text exactly Windows 7 64bit Convert endnotes into plain text exactly Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,369
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

Copying the endnotes to another file is quite simple; preserving their references isn't. Do you want them preserved in both files? I take it, too, you realize they'll no longer function as endnotes once you've done this?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #4  
Old 10-22-2017, 08:18 PM
SlimYooper SlimYooper is offline Convert endnotes into plain text exactly Windows 10 Convert endnotes into plain text exactly Office 2016
Novice
Convert endnotes into plain text exactly
 
Join Date: Oct 2017
Posts: 4
SlimYooper is on a distinguished road
Default

Yes, I realize. Basically, I need to convert thousands of endnotes into a self-contained study-guide to a separate textbook, with graphics and charts added to this guide, so they can't be left as endnotes. I'll add the graphics only after the book is finalized, so I won't need the endnotes to self-update after that (and this way, with section breaks, if anything does get changed, it will only affect one chapter's notes and numbering, so it won't be a complete disaster).

I think I’ve maybe figured out a general idea how it could be solved, but a few things are beyond my newbie VBA skills.
I plan to dim an array
search for each section break
search for the first endnote after the break
record this endnote’s index in my array
then run the macro I presented, but instead of inserting aendnote.Index I’d subtract from it the highest value in my array less than it (+1) and insert that into the study guide, (and convert the index into a letter, that the textbook people prefer).

If anybody’s got an easier way, I’d love to save myself the trouble. Otherwise maybe you can answer a couple things.
If I search for an endnote with a simple Find “^e” how do I extract the index of the endnote I just landed on? Would it be something like Selection.Endnotes.Item.Index? That’s pure guesswork based on the options I got each time I hit a period. I have no idea if I’m on the right track. I assume all these properties are cataloged somewhere, but I'm flying blind. Are there any other landmines you see looming on my path. I’m an old basic programmer (who hasn't programmed in a couple decades), but this is my first significant encounter with VBA and I’m a little out of my depth. (The work is for a non-profit that can't afford a real programmer, so they're stuck with me).
Reply With Quote
  #5  
Old 10-23-2017, 02:59 PM
macropod's Avatar
macropod macropod is offline Convert endnotes into plain text exactly Windows 7 64bit Convert endnotes into plain text exactly Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,369
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

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]
Reply With Quote
  #6  
Old 10-23-2017, 03:25 PM
SlimYooper SlimYooper is offline Convert endnotes into plain text exactly Windows 10 Convert endnotes into plain text exactly Office 2016
Novice
Convert endnotes into plain text exactly
 
Join Date: Oct 2017
Posts: 4
SlimYooper is on a distinguished road
Default

Thanks, that works perfectly.
I think I was maybe getting close to a solution with my own method, but it was a mess, and frustration was rising faster than the problems were getting resolved, so this is much appreciated. I can't say I completely understand how it works, but it works.
Reply With Quote
Reply



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
Convert endnotes into plain text exactly 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 endnotes into plain text exactly Convert image-text hybrids into plain text morlack Excel 4 12-03-2014 05:29 PM
Convert endnotes into plain text exactly 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

Other Forums: Access Forums

All times are GMT -7. The time now is 08:24 AM.


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