简体   繁体   中英

Finding Endnote number with wdRestartSection NumberingRule

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM