![]() |
#1
|
|||
|
|||
![]()
I have created a macro to indent non-numbered paragraphs under Heading 1-7 styles in legal documents. It works to a certain extent. The first part of the code indents paras using Body 1-7 styles under bold heading styles and this part works fine.
The second part of the code is where I am having issues - it is supposed to move the body level back one level but only if the previous heading style is not bold e.g. Body3 becomes Body2. I'm trying to get the code to 'do nothing' if the previous heading is bold but I can't seem to get it work correctly. I would be really grateful if someone could take a look and tell me where I'm going wrong. Thanks TEST DOC FOR BODY LEVELS.docx Code:
Sub BodyLevelParas() Application.ScreenUpdating = False Dim para As Paragraph, nextPara As Paragraph, Rng As Range Dim i As Integer If Selection.Type = wdSelectionIP Then MsgBox Prompt:="You have not selected any text!" Exit Sub End If With Selection.Range Set Rng = Selection.Range With Rng For Each para In .Paragraphs 'Convert non numbered paras to Body Level For i = 1 To 7 If para.Style Like "Heading " & i & "*" Then Set nextPara = para.Next If Not nextPara Is Nothing Then If nextPara.Style = "Body Text" Then nextPara.Style = "Body" & i End If End If End If Next i Next para End With With Selection.Range Set Rng = Selection.Range With Rng.Find For Each para In Rng.Paragraphs 'Move Body Level back one level if previous heading is not bold If para.Range.Style = "Body2" Then If para.Previous.Style = "Heading 2" Then If para.Range.Font.Bold = True Then 'Do nothing if previous heading is bold Else para.Range.Style = "Body1" End If End If End If If para.Range.Style = "Body3" Then If para.Previous.Style = "Heading 3" Then If para.Range.Font.Bold = True Then 'Do nothing if previous heading is bold Else para.Range.Style = "Body2" End If End If End If If para.Range.Style = "Body4" Then If para.Previous.Style = "Heading 4" Then If para.Range.Font.Bold = True Then 'Do nothing if previous heading is bold Else para.Range.Style = "Body3" End If End If End If If para.Range.Style = "Body5" Then If para.Previous.Style = "Heading 5" Then If para.Range.Font.Bold = True Then 'Do nothing if previous heading is bold Else para.Range.Style = "Body4" End If End If End If If para.Range.Style = "Body6" Then If para.Previous.Style = "Heading 6" Then If para.Range.Font.Bold = True Then 'Do nothing if previous heading is bold Else para.Range.Style = "Body5" End If End If End If If para.Range.Style = "Body7" Then If para.Previous.Style = "Heading 7" Then If para.Range.Font.Bold = True Then 'Do nothing if previous heading is bold Else para.Range.Style = "Body6" End If End If End If Next para End With Application.ScreenUpdating = True End With End With End Sub |
Thread Tools | |
Display Modes | |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
![]() |
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 |
![]() |
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 |
![]() |
Hallet | Word | 1 | 05-31-2012 02:37 PM |