Microsoft Word End Notes with code example (VBA,VSTO)

Microsoft Word End Notes with code example (VBA,VSTO)

EndNotes

Represents description or reference about a citation or clause in Word Document. End Notes are references which are tagged at the end of section or page identified by a unique superscript character. It looks like comment when pointer hovered over.

Insert Endnote

Step 1: Highlight text

Step 2: Select References tab and click Insert Endnote or press ALT + CTRL + D key from keyboard

Step 3: A line as separator gets inserted at the end of section by pointing cursor where you can type reference or about selected text. Also if you have a close look at the next to selection a special symbol gets inserted in superscript format.

VBA code example

Public Sub EndNoteExample()
    'Declare object ot hold document
    Dim oDocument As Document
    'Declare object to hold range
    Dim oRange As Range
    
    'Bind active document reference
    Set oDocument = ActiveDocument
    
    'Bind selection
    Set oRange = Selection.Range
    
    'Add end note
    oDocument.Endnotes.Add Range:=oRange, Text:="A Software development company provides end to end I.T. Solutions"
    
    'Cleanup
    If Not oRange Is Nothing Then
        Set oRange = Nothing
    End If
    If Not oDocument Is Nothing Then
        Set oDocument = Nothing
    End If
    
End Sub

C# code example

private void btnInsertNotes_Click(object sender, RibbonControlEventArgs e)
{
	//Declare document object
	wordApp.Document oDocument = Globals.ThisAddIn.Application.ActiveDocument;

	//Declare range object
	wordApp.Range oRange = Globals.ThisAddIn.Application.Selection.Range;

	//Insert Endnote
	oDocument.Endnotes.Add(Range: oRange, Text: "A Software development company provides end to end I.T. Solutions");
}

Next >> Embed or Link Excel File in Word Document Example

Leave a Reply

Your email address will not be published. Required fields are marked *