View Single Post
 
Old 06-09-2022, 01:55 AM
Shelley Lou Shelley Lou is offline Windows 10 Office 2016
Expert
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA Paragraph Indent under Heading styles

Hi Andrew, thank you so much for taking the time to look at the code for me, I have tested your code on a few legal documents this morning and it is brilliant.

I thought I would be able to recreate the same code for Schedule Level numbering / Body styles. I changed Heading to Schedule Level in your code but it didn't work. Do I need to add something to OutlineLevel perhaps?


Code:
Sub BodyLevel_Schedule()
  Dim aPara As Paragraph, iLev As Integer, iStart As Integer, sStyName As String
  Dim bBold As Boolean, aRng As Range
  
  Set aRng = Selection.Range
  If Selection.Type = wdSelectionIP Then
    MsgBox Prompt:="You have not selected any text!"
    Exit Sub
  ElseIf aRng.Paragraphs(1).OutlineLevel = wdOutlineLevelBodyText Then
    iLev = InputBox("What level heading precedes your selected text?", "Starts at Level", "1")
  End If
  
  For Each aPara In aRng.Paragraphs
    sStyName = Split(aPara.Style, ",")(0)   'removes aliases from stylename
    aPara.Range.Select
    Select Case True
      Case sStyName Like "Schedule Level *"           'keep track of the preceding Schedule Level
        iLev = aPara.OutlineLevel
        bBold = aPara.Range.Words(1).Font.Bold
      Case sStyName Like "Body*", sStyName Like "Normal"
        If iLev < 8 And aPara.Range.Characters.Count > 1 Then
          If bBold Then
            aPara.Style = "Body" & iLev
          Else
            aPara.Style = "Body" & iLev - 1
          End If
        End If
    End Select
  Next aPara
End Sub
Reply With Quote