Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #3  
Old 06-09-2022, 01:55 AM
Shelley Lou Shelley Lou is offline VBA Paragraph Indent under Heading styles Windows 10 VBA Paragraph Indent under Heading styles Office 2016
Expert
VBA Paragraph Indent under Heading styles
 
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Paragraph Indent under Heading styles Help Please, IF with Selected Paragraph Format & Left Indent with First Line Indent Cendrinne Word VBA 3 03-06-2022 04:42 AM
How to indent first line from second paragraph of every heading? indra059 Word 3 02-22-2022 08:20 PM
VBA Paragraph Indent under Heading styles Creating buttons for individual paragraph styles on a ribbon tab - not using Quick Styles T7Training Word 11 12-22-2019 12:16 PM
Using numbered list style, how to indent text immediately following heading to match heading indent? SpechtacularDave Word 3 09-25-2019 01:22 PM
VBA Paragraph Indent under Heading styles Styles: Heading 4 stuck at same heading number Hallet Word 1 05-31-2012 02:37 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 11:46 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft