Home > Mobile >  Finding Endnote number with wdRestartSection NumberingRule
Finding Endnote number with wdRestartSection NumberingRule

Time:10-01

I am writing a VBA script to convert endnotes to plain text. This is fairly straightforward when the endnotes have continuous numbers (copy all the end notes to the end of the text, number them using the index, and replace all the references with the indexes).

In this case, however, the endnote numbers are configured to reset every section (NumberingRule=wdRestartSection). This means the index is not the number. I've tried to get the number using endnote.Reference.Text, but this is empty. I haven't found anywhere in the object model that has the actual number for each Endnote.

Is this information available?

Is there a way to walk Endnotes per-section rather than for the entire document so that I could track the index myself?

I'm currently trying to fetch it this way:

For Each objEndnote In ActiveDocument.Endnotes
    print(objEndnote.Reference.Text)
Next

This just prints empty strings.

CodePudding user response:

Looks like there is no number per section - weird. So you have to count it yourself per section:

Option Explicit

Sub getAllEndnotesWithNumbers()

Dim e As Endnote, section As Long, eCounter As Long

For Each e In ThisDocument.Endnotes
    If section <> endnoteSection(e) Then
        section = endnoteSection(e)
        eCounter = 1
        Debug.Print "--- Section " & section & " ----------"
    End If
    
    Debug.Print eCounter, e.Range.Text
    eCounter = eCounter   1
    
Next
    
End Sub

Private Function endnoteSection(e As Endnote) As Long
endnoteSection = e.Range.Sections(1).Index
End Function

  • Related