Converting Footnotes to In-Text Citations

I am having some difficulty with this solution:

I am currently using the VBA macro below to convert a word doc's footnotes into in-text citations to be used within wordpress. The resulting text needs to be copy/pasted into wordpress. The [ref] tags seen in the code are to enable wordpress to read the text as citations.

Sub foot2inline()
Dim oFeets As Footnotes
Dim oFoot As Footnote
Dim oRange As Range
Dim szFootNoteText As String

' Grabs the collection of FootNotes
Set oFeets = Word.ActiveDocument.Footnotes

' Iterates through each footnote
For Each oFoot In oFeets

	szFootNoteText = oFoot.Range.Text
	'Start search from beginning of document
	Selection.HomeKey Unit:=wdStory
	With Selection.Find
		.Text = "^f" ' Looks for all footnotes
		.Forward = True
		.Wrap = wdFindStop
	End With
	' Delete the footnote
	'Insert the footnote text
	'Here you do whatever format tickles your fancy
	Selection.Text = " [ref] " + szFootNoteText + "[/ref] "

	'CHANGE COLOR HERE. Color code is below.
	Selection.Font.Color = 6299648

	'Disables undo to save memory on very large documents.
End Sub

I have two issues I need resolved:

  1. When the footnote is moved into the text, I lose all formatting (italicization, small/large caps, etc). It is crucial that formatting is preserved because the footnotes are legal (bluebook) citations and the formatting is essential. Toggling the Selection.Find.ClearFormatting does not do the trick.
  2. The result of the macro puts a weird box after the [ref] but before the footnote's text. I suspect that this is a remnant of the numbering within footnotes. This box cannot be present after the macro runs. 

Ideally this needs to run in both Office and Office for Mac.

Any suggestions, tips, or references would be much appreciated!


Some alternative code to play with:

Sub Demo()
Application.ScreenUpdating = False
Dim i As Long, RngNt As Range, RngTxt As Range
With ActiveDocument
  For i = .Footnotes.Count To 1 Step -1
    With .Footnotes(i)
      Set RngNt = .Range
      With RngNt
        .End = .End - 1
        .Start = .Start + 2
      End With
      Set RngTxt = .Reference
      With RngTxt
        .InsertAfter " [ref]"
        .Collapse wdCollapseEnd
        .InsertAfter "[/ref]"
        .Collapse wdCollapseStart
        .FormattedText = RngNt.FormattedText
      End With
    End With
End With
Application.ScreenUpdating = True
End Sub

Paul Edstein
(Fmr MS MVP - Word)

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.


Question Info

Last updated January 1, 2020 Views 1,766 Applies to: