Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-14-2022, 04:11 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

Test Doc to replace non numbered paras under numbered paras.docx

Hi, I'm hoping someone can help me with a macro I am trying to create that indents non-numbered paragraphs under Heading 1-7 but ignores if the next paragraph is a heading number, so:

Heading 1 = Body1
Heading 2 = Body2


Heading 3 = Body3
Heading 4 = Body4
Heading 5 = Body5
Heading 6 = Body6
Heading 7 = Body7

So far the code works for Heading 1 but is removing the heading 2 numbering and making those as Body1. I haven't got as far as adding in the other heading/body levels until I can sort out this problem first.

If anyone can advise what I'm missing in the code I would be really grateful.
Thanks, Shelley


Code:
Sub ChangeParasAfterHeading()
    Dim para As Paragraph, nextPara As Paragraph, oRng As Range
    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
        If para.Style = "Heading 1" Then
            Set nextPara = para.Next
            If Not nextPara Is Nothing Then
                nextPara.Style = "Body1"
    Else
    If para.Style = "Heading 2" Then
            Set nextPara = para.Next
            If Not nextPara Is Nothing Then
                nextPara.Style = "Body2"
                Else
            End If
        End If
        End If
        End If
    Next
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 08:29 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