Skip to content

Instantly share code, notes, and snippets.

@johndyer
Created December 8, 2020 15:26
Show Gist options
  • Save johndyer/f53be588a84dd1a0da7b02310671dc1a to your computer and use it in GitHub Desktop.
Save johndyer/f53be588a84dd1a0da7b02310671dc1a to your computer and use it in GitHub Desktop.
Moves citations from Endnote X that are in the main text (Dyer, 2018) of a Word document to a Footnote
' adapted from https://community.endnote.com/t5/EndNote-How-To/Converting-in-text-citations-to-footnotes-endnotes/td-p/4438/page/2
Public Sub ConvertInTextEndnotesToFootnote()
Dim oField As Field
Dim sCode As String
Dim sSuffix As String
Dim sSuffixLeft As String
Dim sSuffixRight As String
Dim pos1 As Long
Dim pos2 As Long
'Loop through all fields in the document
For Each oField In ActiveDocument.Fields
'Skip fields that aren't EndNoteX
If InStr(oField.Code.Text, "EN.CITE") = 0 Then GoTo Bypass:
oField.Select
sCode = oField.Code.Text
'If author is excluded, show the author (optional)
If InStr(sCode, "ExcludeAuth=""1""") > 0 Then
oField.Code.Text = Replace(sCode, "ExcludeAuth=""1""", "")
End If
'Cut the citation to move it
Selection.Cut
'Add temporary bookmark where the citation was, so we can return to it after creating the footnote
With ActiveDocument.Bookmarks
.Add Range:=Selection.Range, Name:="tempqxtz"
.DefaultSorting = wdSortByName
.ShowHidden = False
End With
'Add the Footnote (change to "Endnotes" if desired)
ActiveDocument.Footnotes.Add Range:=Selection.Range, Reference:=""
Selection.Paste
'Return to position in document
Selection.GoTo What:=wdGoToBookmark, Name:="tempqxtz"
'Delete the temporary bookmark
ActiveDocument.Bookmarks("tempqxtz").Delete
Bypass:
Next oField
MsgBox "Process Complete", vbOKOnly + vbInformation, "Convert In-text Citations to Footnotes"
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment