View Single Post
 
Old 04-15-2021, 04:05 PM
Guessed's Avatar
Guessed Guessed is offline Windows 10 Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,977
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

Assuming each additional style is being treated exactly the same way, I would add an array of the target style names and loop it like this
Code:
Sub MarkBodyText()
  ' Author:    A. Lockton (a/k/a Guessed) via msofficeforums.com
  ' Date:      April 2021
  ' Notes:     Adds "(XX)" at start of everypara styled as specified
  Dim arrStyles() As String, i As Integer
  arrStyles = Split("Body Text|Heading 1|Heading 2", "|")  'list of style names
  Application.ScreenUpdating = False
  For i = LBound(arrStyles) To UBound(arrStyles)
    With ActiveDocument.Content.Find
     .ClearFormatting
     .Style = arrStyles(i)      
      Do While .Execute(Forward:=True, Format:=True) = True
       With .Parent
         If Left(.Text, 1) = vbCr Or Left(.Text, 1) = " " Or Left(.Text, 1) = Chr(12) Then
           'do nothing
         Else
           .InsertBefore "(XX) "
         End If
  
         If .End = ActiveDocument.Content.End Then
           Exit Do
         Else
           .Move Unit:=wdParagraph, Count:=1
         End If
       End With
     Loop
    End With
  Next i
  Application.ScreenUpdating = True
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia

Last edited by Charles Kenyon; 04-16-2021 at 01:21 AM.
Reply With Quote