View Single Post
 
Old 06-11-2017, 07:00 AM
gmaxey gmaxey is offline Windows 7 32bit Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Something like this:

Code:
Sub ScratchMacro()
'A basic Word macro coded by Greg Maxey
Dim oDict
Dim oDocNotes As Document, oDocText As Document
Dim oRng As Range
Dim strNote As String
Dim oNote As Endnote
  'Create a dictionary containing the defined endnote text.  Note references "must" be unique.
  Set oDict = CreateObject("Scripting.Dictionary")
  Set oDocNotes = Documents.Open("C:\Users\Maxey\Desktop\befor run vb2.txt", , , False, , , , , , , , False)
  Set oRng = oDocNotes.Range
  With oRng.Find
    .Text = "(endendnote)(*)(startendnote)"
    .MatchWildcards = True
    .Replacement.Text = "\2"
     While .Execute(Replace:=wdReplaceOne)
       strNote = oRng.Paragraphs(1).Range.Text
       strNote = Trim(Replace(strNote, oRng.Text, ""))
       oDict.Add oRng.Text, strNote
       oRng.Collapse wdCollapseEnd
     Wend
  End With
  oDocNotes.Close wdDoNotSaveChanges
  'Open the text document and replace the flags with the matching dictionary item
  Set oDocText = Documents.Open("C:\Users\Maxey\Desktop\befor run vb1.txt")
  Set oRng = oDocText.Range
  With oRng.Find
    .Text = "(endendnote)(*)(startendnote)"
    .MatchWildcards = True
    .Replacement.Text = "\2"
     While .Execute(Replace:=wdReplaceOne)
       Set oNote = ActiveDocument.Endnotes.Add(oRng, oRng.Text, oDict.Item(oRng.Text))
       If Asc(oNote.Range.Characters.Last) = 13 Then
         oNote.Range.Characters.Last.Delete
        End If
       oRng.Delete
     Wend
  End With
lbl_Exit:
  Exit Sub
End Sub
P.S. before is spelled with an ending e
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote