Quote:
Originally Posted by egyblind
hello
yes i want to embed footnote and endnote definitions in the body text and put "fn" / "en" before the text to be known its footnote / endnote.
|
This should do it:
Code:
'---------------------------------------------------------------------------------------
' Method : Notes2Inline
' Author : Kim
' Date : 11-02-2017
' Purpose: Convert footnotes/endnotes to inline text
'---------------------------------------------------------------------------------------
Sub Notes2Inline()
Dim oFNs As Footnotes
Dim oFN As Footnote
Dim oENs As Endnotes
Dim oEN As Endnote
Dim oRng As Range
Dim strFNText As String
Dim strENText As String
Dim lngIndex As Long 'variable for note number. If not wanted, remove _
" & lngIndex & " (including qoutation marks) from the With oRng.Text lines below
Set oFNs = Word.ActiveDocument.Footnotes
For Each oFN In oFNs
strFNText = oFN.Range.Text
lngIndex = lngIndex + 1
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "^f" ' Looks for all footnotes
.Forward = True
.Wrap = wdFindStop
If .Execute Then
oFN.Delete
With oRng
.Text = " [Footnote " & lngIndex & ": " & strFNText & "]"
.Font.Color = wdColorDarkBlue 'Color text taken from endnotes blue
End With
End If
End With
'Uncomment to disable undo to save memory on very large documents.
'ActiveDocument.UndoClear
Next
Set oENs = Word.ActiveDocument.Endnotes
For Each oEN In oENs
strENText = oEN.Range.Text
lngIndex = lngIndex + 1
Set oRng = ActiveDocument.Range
With oRng.Find
.Text = "^e" ' Looks for all endnotes
.Forward = True
.Wrap = wdFindStop
If .Execute Then
oEN.Delete
With oRng
.Text = " [Endnote " & lngIndex & ": " & strENText & "]"
.Font.Color = wdColorDarkRed 'Color text taken from endnotes red
End With
End If
End With
'Uncomment next line to disable undo to save memory on very large documents.
'ActiveDocument.UndoClear
Next
End Sub
To be honest, I didn't forge the code myself, found it by a google search for "vba footnote to text" and modified it a little to cater for endnotes as well
Regards,
Kim