0
votes

Our Notes section allows for the use of non-standard paragraph styles for an endnote, when it has more than one paragraph in the note. For example, each endnote is set up as follows:

  • Endnote Reference + Endnote Text: for first paragraph in the endnote
  • the following paragraphs, can use styles such as "poem," "extract," "p," etc.

I'm trying to loop through each note to determine the styles used. If the first paragraph style is NOT "Endnote Text" then the style will be changed to this default style. That works! The NEXT paragraph style, if it exists, is then checked to determine its style name. I would like to allow for styles OTHER than just "Endnote Text" but it looks like using "ActiveDocument.Endnotes(n).Range.Select" is causing ALL styles to change to "Endnote Text." How can I loop through each paragraph style within the endnote selected?

For n = 1 To EndnoteCount ActiveDocument.Endnotes(n).Range.Select

            CurrStyName = CurrSty.NameLocal

            If Not (CurrStyName = "Endnote Text") The
                CurrStyName = "Endnote Text"
                ReportString = ReportString + vbNewLine + "The style " & CurrStyName & " is reverting to the default Endnote Text style for endnote#" + Str(n) + "."
            End If

        Set CurrSty2 = Selection.Next.ParagraphStyle

...

1

1 Answers

0
votes

ActiveDocument.Endnotes(n).Range contains all the paragraphs for the endnote so when you select it and apply a style you change all the paragraphs.

What you need to do is loop through the endnotes and then through the paragraphs for each endnote, without selecting them, something like this:

  Dim para As Long
  For n = 1 To ActiveDocument.Endnotes.Count
    With ActiveDocument.Endnotes(n).Range
      For para = 1 To .Paragraphs.Count
        CurrStyName = .Paragraphs(para).style.NameLocal
        If Not (CurrStyName = "Endnote Text") Then
          'do whatever you need here
        End If
      Next para
    End With
  Next n