![]() |
|
#2
|
||||
|
||||
|
Try this way of doing it. I added an inputbox to deal with a situation where the first selected paragraph isn't a heading.
Code:
Sub ApplyNormNumStyles()
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 "Heading *" 'keep track of the preceding heading 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
__________________
Andrew Lockton Chrysalis Design, Melbourne Australia |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
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 |
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 |
Styles: Heading 4 stuck at same heading number
|
Hallet | Word | 1 | 05-31-2012 02:37 PM |