Accessing a Footnote Number in VBA

Written by Allen Wyatt (last updated November 27, 2023)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365


2

Paul is trying to use Word VBA to return the footnote number of the footnote in which the insertion point is located. In his case, it is possible that the footnote contains more than one paragraph. Paul wonders if there is a way to determine this footnote number in VBA.

It is possible to determine a footnote number by using the Index property of a footnote object. Here's a quick way to demonstrate how this info can be useful:

Sub GetFootnoteNumber()
    Dim f As Footnote
    Dim sTemp As String

    sTemp = "The insertion point is not in a footnote"
    For Each f In ActiveDocument.Footnotes
        If Selection.InRange(f.Range) Then
            sTemp = "The insertion point is in footnote " & f.Index
        End If
    Next
    MsgBox sTemp
End Sub

Note that the macro steps through each footnote in the document. If it is determined that the selection (insertion point) is in a particular footnote, then the Index property of that footnote is used to put a message in the sTemp variable. Once done looping through the footnotes, the sTemp variable is displayed in a message box.

If you have a lot of footnotes in your document, you might not want to loop through all of them. In that case, you can use the Information property of the selection to determine if the insertion point is currently in a footnote, in this manner:

Sub GetFootnoteNum()
    Dim J As Integer
    Dim sTemp As String

    sTemp = "The insertion point is not in a footnote"
    If Selection.Information(wdInFootnote) Then
        J = Selection.Paragraphs(1).Range.Footnotes(1).Index
        sTemp = "The insertion point is in footnote " & J
    End If
    MsgBox sTemp
End Sub

In addition, you can derive other information about a particular footnote by expanding what properties of that footnote you access. The following macro returns not only the footnote number, but also the numbering rule, the numbering style, and the starting number for the footnotes:

Sub GetFootnoteInfo()
    Dim f As Footnote
    Dim sTemp As String
    
    sTemp = "The insertion point is not in a footnote"
    If Selection.Information(wdInFootnote) Then
        Set f = Selection.Paragraphs(1).Range.Footnotes(1)
        sTemp = "Footnote number: " & f.Index & vbCr
        With f.Range.FootnoteOptions
            sTemp = sTemp & "Numbering Rule: " & .NumberingRule & vbCr & _
              "Numbering Style: " & .NumberStyle & vbCr & _
              "Starting Number: " & .StartingNumber
        End With
    End If
    MsgBox sTemp
End Sub

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (5906) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Shortcut for Full Screen Reading View

Want to get rid of almost everything on the screen except your document? Here's how to easily maximize what you see.

Discover More

Seeing Where Bookmarks Are

Bookmarks can be great for referencing and finding portions of your document. If you want to easily see where the ...

Discover More

Converting Paragraphs to Comments

Want to pull text from a bunch of paragraphs and stuff that text into comments? It's easy to do using the macro presented ...

Discover More

Learning Made Easy! Quickly teach yourself how to format, publish, and share your content using Word 2013. With Step by Step, you set the pace, building and practicing the skills you need, just when you need them! Check out Microsoft Word 2013 Step by Step today!

More WordTips (ribbon)

Toggling Font Assignments in a Macro

If you need to quickly switch a text selection from one typeface to another, one way you can do it is with a macro. This ...

Discover More

Changing the Format of Existing Dates

There are a myriad of ways in which a date can be formattedâ€"day first, month first, number of digits in the year, etc. ...

Discover More

Detecting the Beginning of a Sentence in a Macro

Macros can make life easier, as they provide a fast and efficient way of processing text in a document. Such is the case ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 7 + 0?

2020-04-19 05:07:51

Ken

A selection can contain more than one paragraph and you need to specify specify which. If the selection is only only part of a paragraph or is an insertion point in the paragraph, then you must still specify the first (1) and you will get the the whole paragraph.

In a similar way, a range could contain multiple footnotes so you need to specify the first even though in this case it will have only one.

The logic of the compound statement is:
"Selection.Paragraphs(1)" gives a Paragraph object
".Range" gives the range of the paragraph
".Footnotes(1)" gives the Footnote object of the first footnote in the range
".Index" gives the index number of the Footnote object.


2020-04-18 04:51:08

Simon Freeman

I am a bit puzzled. Why the "1" in brackets after Paragraphs and Footnotes in: "Set f = Selection.Paragraphs(1).Range.Footnotes(1)"? Thanks.


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Videos
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.