Microsoft Word Reference Footnote with code example

Microsoft Word Reference Footnote with code example

Footnote

A note written at the bottom of the page which provides more information about something (Citation, terms, links, shapes etc.) in your document. Each Footnote can be identified by a unique reference number, inserted as superscript. A footnote can be inserted by following below steps:

Insert Footnote

Step 1: Select text or range for which you want to put reference notes as shown below:

Step 2: Select References tab and click on Insert Footnote button, it brings cursor at the bottom of the page by inserting Footnote block where you can write you footnote as shown below:

Notice, arrows pointing to superscript “1” which is reference number for inserted footnote, if you hover mouse over “1” it shows a tool-tip text containing reference text written in the footnote.

Add code example

Syntax

Document.Footnotes.Add(Range, Reference, Text)

Parameters

  1. Range: a required parameter as range, refers to range or selection on which the footnote needs to be inserted.
  2. Reference: an optional parameter where user can specify his own reference as a string if not provided Word inserts default reference character.
  3. Text: an optional parameter as text, refers to text that you would like to insert as footnote text to describe reference.

Example

Public Sub InsertFootNoteExample()
    'Declare object to hold document
    Dim oDoc As Document
    
    'Bind active document reference
    Set oDoc = ActiveDocument
    
    'Declare object to hold range
    Dim oRange As Range
    
    'Bind selection into range
    Set oRange = Selection.Range
    
    'Insert footnote
    oDoc.Footnotes.Add Range:=oRange, Reference:="k", Text:="A perfect blogging site with complete VBA solution"
    
    'cleanup
    If Not oRange Is Nothing Then
        Set oRange = Nothing
    End If
    If Not oDoc Is Nothing Then
        Set oDoc = Nothing
    End If
End Sub

Output

Count property

Public Sub CountFootnoteExample()
    'Declare object to hold document
    Dim oDoc As Document
    
    'Bind active document reference
    Set oDoc = ActiveDocument
    
    MsgBox oDoc.Footnotes.Count
    
    'cleanup
    If Not oDoc Is Nothing Then
        Set oDoc = Nothing
    End If
End Sub

Output

Delete method

Public Sub DeleteFootnoteExample()
    'Declare object to hold document
    Dim oDoc As Document
    
    'Bind active document reference
    Set oDoc = ActiveDocument
    
    oDoc.Footnotes(1).Delete
    
    'cleanup
    If Not oDoc Is Nothing Then
        Set oDoc = Nothing
    End If
End Sub

Footnotes collection

Public Sub IterateFootnotesExample()
    'Declare object to hold document
    Dim oDoc As Document
    
    'Bind active document reference
    Set oDoc = ActiveDocument
    
    Dim oFootNote As Footnote
    'Print reference and text of each reference
    For Each oFootNote In oDoc.Footnotes
        Debug.Print oFootNote.Reference & " is reference for : " & oFootNote.Range.Text
    Next oFootNote
    
    
    'cleanup
    If Not oFootNote Is Nothing Then
        Set oFootNote = Nothing
    End If
    If Not oDoc Is Nothing Then
        Set oDoc = Nothing
    End If
End Sub

ContinuationNotice property

Allows continue notice for footnotes in the document. Below code will put “Continue…”:

Public Sub ContinueNoticeFootnoteExample()
    'Declare object to hold document
    Dim oDoc As Document
    
    'Bind active document reference
    Set oDoc = ActiveDocument
    
    oDoc.Footnotes.ContinuationNotice.Delete
    oDoc.Footnotes.ContinuationNotice.InsertBefore "Continue..."
    
    'cleanup
    If Not oDoc Is Nothing Then
        Set oDoc = Nothing
    End If
End Sub

ContinuationSeparator property

Can customize continuation separator in the footnotes inserted in the document.

Public Sub ContinuationSeparatorFootnoteExample()
    'Declare object to hold document
    Dim oDoc As Document
    
    'Bind active document reference
    Set oDoc = ActiveDocument
    
    'Delete previous separator
    oDoc.Footnotes.ContinuationSeparator.Delete
    oDoc.Footnotes.ContinuationSeparator.InsertBefore "=============="
    
    'cleanup
    If Not oDoc Is Nothing Then
        Set oDoc = Nothing
    End If
End Sub

Next >> List of Fonts in Microsoft Word with code example

Leave a Reply

Your email address will not be published.