Extract Footnotes from Word to Excel with its reference sentence

B . Ni 1 Reputation point
2022-08-03T11:50:15.497+00:00

Hi,
I found a macro (the following code) to take footnotes info from a word document and insert them to an Excel document- the footnote reference in the first column, the page on which the footnote appears in the second column and the text of the footnote in the third column.

I would like to have also on my excel a column for the sentence in the word document that the footnotes reference.

Any help?

Sorry but I do not know VBA and just found the below macro by searching and tested it.

Sub ExtractFootnotes()
Dim xlapp As Object
Dim xlbook As Object
Dim xlsheet As Object
Dim i As Long, lognum As Long
Dim fnote As Footnote
On Error Resume Next
Set xlapp = GetObject(, "Excel.Application")
If Err Then
bstartApp = True
Set xlapp = CreateObject("Excel.Application")
End If
On Error GoTo 0
Set xlbook = xlapp.Workbooks.Add
Set xlsheet = xlbook.Worksheets(1)
With xlsheet.Range("A1")
.Offset(0, 0).Value = "Foonote Ref"
.Offset(0, 1).Value = "Page"
.Offset(0, 2).Value = "Footnote Text"
i = 1
For Each fnote In ActiveDocument.Footnotes
.Offset(i, 0).Value = fnote.Index
.Offset(i, 1).Value = fnote.Range.Information(wdActiveEndPageNumber)
.Offset(i, 2).Value = fnote.Range.Text
i = i + 1
Next fnote
End With
xlapp.visible = True
xlbook.Activate
Set xlapp = Nothing
Set xlbook = Nothing
Set xlsheet = Nothing
End Sub

Microsoft 365 and Office | Word | For business | Windows
Developer technologies | Visual Basic for Applications
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Viorel 122.6K Reputation points
    2022-08-04T05:42:02.67+00:00

    Try adding

    .Offset(i, 3).Value = fnote.Reference.Sentences(1)

    before i = i + 1.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.