Converting in-text citations to footnotes/endnotes

Hi all …

I needed to convert in-text refs like (Jones 2010:23) or (Peters 2011:19-23) to footnote refs of the format

…, p. 23.

…, pp. 19-23.

and if the in-text citation does not show the author, then switch author on in the footnote

This macro is a modification of the one posted by Miriam way back in 2009 from one created by Shyam Ranganathan.

I have removed redundant code (which you get when you record a macro), and added comments so those not too familiar with VBA can see what’s happening.

You can un-comment the message boxes (just delete ’ in 'MsgBox …) to see what’s happening.

The code could be improved further, but it works OK … at least for me (Word 2007, Windows 7).

Happy conversions!!!

PS: To make this work for Endnotes just change ActiveDocument.Footnotes.Add to ActiveDocument.Endnotes.Add


Public Sub ConvertIntextToFootnote()

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

    'Is the field an Endnote field?
    
    If InStr(oField.Code.Text, “EN.CITE”) = 0 Then GoTo Bypass:
    
    oField.Select
    
    'Modify the Suffix in the field code … <Suffix>text</Suffix>, if one exists

    sCode = oField.Code.Text
    'MsgBox sCode
    pos1 = InStr(sCode, “<Suffix>”)
    
    If pos1 > 0 Then 'suffix exists, so extract it
    
        sSuffixLeft = Left(sCode, pos1 + 7)
        'MsgBox sSuffixLeft
        pos2 = InStr(sCode, “</Suffix>”)
        sSuffixRight = Right(sCode, Len(sCode) - pos2 + 1)
        'MsgBox sSuffixRight
        sSuffix = Mid(sCode, pos1 + 8, pos2 - (pos1 + 8))
        'MsgBox sSuffix
        
        'If no dash, replace : with p. else with  pp.

        If InStr(sSuffix, “-”) > 0 Then
            sSuffix = Replace(sSuffix, “:”, " pp. ")
        Else
            sSuffix = Replace(sSuffix, “:”, " p. ")
        End If
        
        'Add a full stop

        sSuffix = sSuffix + “.”
        'MsgBox sSuffix
        
        'Now rebuild the code

        sCode = sSuffixLeft + sSuffix + sSuffixRight

        'Set the new code in the field

        oField.Code.Text = sCode
        'MsgBox oField.Code.Text
        
    End If
    
     'If author is excluded, show the author
        
        If InStr(sCode, “ExcludeAuth=”“1"”") > 0 Then
        
            oField.Code.Text = Replace(sCode, “ExcludeAuth=”“1"”", “”)
            
        End If
    
    Selection.Cut
    
    'Add temporary bookmark so we can return to the Main Story

    With ActiveDocument.Bookmarks
        .Add Range:=Selection.Range, Name:=“tempqxtz”
        .DefaultSorting = wdSortByName
        .ShowHidden = False
    End With
            
    'Add the Footnote

    ActiveDocument.Footnotes.Add Range:=Selection.Range, Reference:=""
    Selection.Paste
    
    'Return to Main Story

    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


1 Like

Dear Miriam,

I have a phd thesis which I have to organize according to author-date style. My references are improperly cited and are in different styles, so I just downloaded the Endnote trial version to help me organize references and bibliography. This is my first encounter with this program and I am having some difficulties.

So I have a cople of quesitons:

  1. I need to transfer each reference manually from my thesis in Word, into Endnote, is that right?

  2. My references are not properly written, so I thought that inserting them into Endnote and indicating the style I need, the program would automatically correct the references, or do I have to break down each reference myself and put each part of the reference in appropriate window? i.e. author in the author window, year in the year window,etc. This would require huge work ! I thought that Endnote did this, maybe I didn’t understand, could you please help me figure out how to do that? 

Thanks in advance

here is  free movie sites  to watch you favorite movies online.

I commend your hard work on this and thank you for this information. You’ve got what it takes to get attention