View Single Post
 
Old 11-08-2023, 08:59 PM
gmaxey gmaxey is online now Windows 10 Office 2019
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,437
gmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the roughgmaxey is a jewel in the rough
Default

You certainly don't (and rarely do) need to use selection. You will have to substitute your own style names:


Code:
Sub ScratchMacro()
'A basic Word Macro coded by Gregory K. Maxey
Dim oPar As Paragraph
Dim oRng As Range
  With ActiveDocument
    Set oRng = .Range
    .Paragraphs(1).Range.Style = "Heading 1"
    .Paragraphs(2).Range.Style = "Heading 2"
    .Paragraphs(3).Range.Style = "Heading 3"
    oRng.Start = .Paragraphs(4).Range.Start
  End With
  'Format unnumbered subtitles
  For Each oPar In oRng.Paragraphs
    If oPar.Range.ComputeStatistics(wdStatisticLines) = 1 _
         And oPar.Range.ParagraphFormat.Alignment = wdAlignParagraphLeft _
         And Not oPar.Range Like "*[0-9]*" Then
      oPar.Range.Style = "Body Text"
    End If
  Next oPar
lbl_Exit:
  Set oPar = Nothing
  Exit Sub
End Sub
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote