Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #7  
Old 01-17-2022, 07:34 AM
Shelley Lou Shelley Lou is offline VBA Help Indent Paragraphs between Headings Windows 10 VBA Help Indent Paragraphs between Headings Office 2016
Expert
VBA Help Indent Paragraphs between Headings
 
Join Date: Dec 2020
Posts: 259
Shelley Lou is on a distinguished road
Default VBA Help Indent Paragraphs between Headings

I have been working on updating the code over the weekend and have now got the code to update the body levels to be directly under the previous clause number if there are 2 or more clauses above the non-numbered text.

I just need to fathom out how to remove the numbering if there is only one paragraph between two headings now which I'm sure I'll get there in the end, I will keep researching until I find the answer.

Massive thank you to this forum and Graham in particular for helping me get this far with the code, couldn't have done it without you.

Code:
Sub TestChangeParas()
Dim para As Paragraph, nextPara As Paragraph
Dim oRng As Range
Dim i As Integer
    If Selection.Type = wdSelectionIP Then
        MsgBox Prompt:="You have not selected any text!"
        Exit Sub
    End If
    Set oRng = Selection.Range
    With oRng
        For Each para In oRng.Paragraphs
            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
    Set oRng = Selection.Range
    With oRng.Find
    .Font.Bold = False
     For Each para In oRng.Paragraphs
     If para.Range.Style = "Body2" Then
     If para.Previous.Style = "Heading 2" Then
     para.Range.Style = "Body1"
End If
End If
If para.Range.Style = "Body3" Then
If para.Previous.Style = "Heading 3" Then
para.Range.Style = "Body2"
End If
End If
If para.Range.Style = "Body4" Then
If para.Previous.Style = "Heading 4" Then
para.Range.Style = "Body3"
End If
End If
If para.Range.Style = "Body5" Then
If para.Previous.Style = "Heading 5" Then
para.Range.Style = "Body4"
End If
End If
If para.Range.Style = "Body6" Then
If para.Previous.Style = "Heading 6" Then
para.Range.Style = "Body5"
End If
End If
If para.Range.Style = "Body7" Then
If para.Previous.Style = "Heading 7" Then
para.Range.Style = "Body6"
End If
End If
Next
lbl_Exit:
    Set para = Nothing
    Set nextPara = Nothing
    Set oRng = Nothing
    Exit Sub
    End With
End Sub
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
VBA Help Indent Paragraphs between Headings Selectively numbered paragraphs based on headings.. WildfireS3 Word 2 05-18-2020 05:18 AM
Indent on headings nerion Word 5 04-11-2019 04:48 AM
Difference between first line Indent and Left Indent kingston123 Word 3 09-25-2018 02:47 PM
Indent of first numbered heading different from subsequent headings ultimateguy Word 1 08-12-2015 06:51 AM
VBA Help Indent Paragraphs between Headings Problem with bold numbers in multi-level list styles when having numbered headings AND paragraphs bwofficer Word 2 12-12-2014 12:21 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:23 AM.


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