Share via

Macro to Pull Footnotes

Anonymous
2014-08-19T05:36:45+00:00

Hi All -

First off thanks as always - always appreciate the advice given here.

Is there a macro available (or would it be possible to create one) that pulls all footnotes and preferably puts them in a table. I have documents (many) with 200+ footnotes that I want each footnote in a new row in a table. If that's not possible - at least copying them unformatted to a new document would be an okay start.

Again thanks!

Microsoft 365 and Office | Word | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
2014-08-20T01:21:34+00:00

I believe that it did insert the footnotes into a table, but the table did not have borders applied to it and perhaps you did not have the Show Gridlines set.

However, the following code will retain any formatting applied to the footnote and also include in the first column of the table the footnote Index number.  Borders will also be applied to the table.

Dim afn As Footnote

Dim docsource As Document

Dim doctarget As Document

Dim rngtarget As Range

Set docsource = ActiveDocument

Set doctarget = Documents.Add

With docsource

    For Each afn In .Footnotes

        Set rngtarget = doctarget.Range

        rngtarget.Collapse wdCollapseEnd

        rngtarget.InsertAfter afn.Index & vbTab

        rngtarget.Collapse wdCollapseEnd

        rngtarget.FormattedText = afn.Range.FormattedText

        rngtarget.Collapse wdCollapseEnd

        rngtarget.InsertAfter vbCr

    Next

End With

doctarget.Range.ConvertToTable

With doctarget.Tables(1).Borders

    .InsideLineStyle = wdLineStyleSingle

    .OutsideLineStyle = wdLineStyleSingle

End With

Was this answer helpful?

0 comments No comments

7 additional answers

Sort by: Most helpful
  1. Anonymous
    2014-08-20T02:14:50+00:00

    I believe that it did insert the footnotes into a table, but the table did not have borders applied to it and perhaps you did not have the Show Gridlines set.

    However, the following code will retain any formatting applied to the footnote and also include in the first column of the table the footnote Index number.  Borders will also be applied to the table.

    Dim afn As Footnote

    Dim docsource As Document

    Dim doctarget As Document

    Dim rngtarget As Range

    Set docsource = ActiveDocument

    Set doctarget = Documents.Add

    With docsource

        For Each afn In .Footnotes

            Set rngtarget = doctarget.Range

            rngtarget.Collapse wdCollapseEnd

            rngtarget.InsertAfter afn.Index & vbTab

            rngtarget.Collapse wdCollapseEnd

            rngtarget.FormattedText = afn.Range.FormattedText

            rngtarget.Collapse wdCollapseEnd

            rngtarget.InsertAfter vbCr

        Next

    End With

    doctarget.Range.ConvertToTable

    With doctarget.Tables(1).Borders

        .InsideLineStyle = wdLineStyleSingle

        .OutsideLineStyle = wdLineStyleSingle

    End With

    With a big thank you from the our law school! This works fantastic. One interesting thing is that there is a tab after every number - but that's a really minor issue. Next I'll be working on setting up an excel macro to take this data and put it in the final form that we'll use on our projects.

    Tremendous thank you from myself and my colleagues.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2014-08-19T14:16:38+00:00

    Run a macro containing the following code when the document containing the footnotes is the active document.

    Dim afn As Footnote

    Dim docsource As Document

    Dim doctarget As Document

    Set docsource = ActiveDocument

    Set doctarget = Documents.Add

    With docsource

        For Each afn In .Footnotes

            doctarget.Range.InsertAfter afn.Range & vbCr

        Next

    End With

    doctarget.Range.ConvertToTable

    So the first method did not work but this one got very very close. It copies the footnotes to a new document but does not convert the document to a table with each footnote in a new row. That being said this is a great start.

    Couple issues/questions:

    1. Formatting isn't maintained. This is for a law review so it's really important that formatting is maintained (italics, small caps, etc...)
    2. The footnote # is being stripped out which was expected but is there a way for me to at least manually get the macro to include the footnote number
    3. Still would be best if I could get in a table - if not, maybe some kind of manual divider between each entry (even like -----------------------------------------) so I can quickly copy to a table once it's done.

    Thanks!

    Best,

    Joel

    Was this answer helpful?

    0 comments No comments
  3. Doug Robbins - MVP - Office Apps and Services 323.1K Reputation points MVP Volunteer Moderator
    2014-08-19T08:16:56+00:00

    Run a macro containing the following code when the document containing the footnotes is the active document.

    Dim afn As Footnote

    Dim docsource As Document

    Dim doctarget As Document

    Set docsource = ActiveDocument

    Set doctarget = Documents.Add

    With docsource

        For Each afn In .Footnotes

            doctarget.Range.InsertAfter afn.Range & vbCr

        Next

    End With

    doctarget.Range.ConvertToTable

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2014-08-19T07:46:17+00:00

    jjmadero,

    1. In a copy of your document, it is possible to change all footnotes in endnotes.

    Then at the end of the document you will have a list of all your endnotes.

    or

    1. With the next macro in a module of your document, the tekst of all footnotes of the document are placed in a table in a new document:

    Sub ExtractFootNotes()

        Dim ftn As Footnote

        Dim wdd As Word.Document

        Dim wddNew As Word.Document

        Dim tbl As Table

        Dim rw As Row

        Set wdd = ThisDocument

        Set wddNew = Application.Documents.Add

        Set tbl = wddNew.Tables.Add(wddNew.Range(0), 1, 2, wdWord9TableBehavior)

        Set rw = tbl.Rows(1)

        For Each ftn In wdd.Footnotes

            rw.Cells(1).Range = ftn.Range

            Set rw = tbl.Rows.Add

        Next

    End Sub

    Jan

    Was this answer helpful?

    0 comments No comments