View Single Post
 
Old 11-08-2023, 09:58 AM
RobiNew RobiNew is offline Windows 10 Office 2016
Competent Performer
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default Formatting specific paragraphs with styles without using Selection

I need to format certain paragraphs with styles, but apart from the fact that I do not want to use Selection, my code here below produces unsatisfactory results. Can someone help? Thanks!
Code:
'Formatting first three paragraphs
Dim parRng As Range
Set parRng = ActiveDocument.Paragraphs(1).Range
parRng.Select
parRng.Style = ActiveDocument.Styles("AuthorPar")
   parRng.Move Unit:=wdParagraph, Count:=1
parRng.Select
parRng.Style = ActiveDocument.Styles("LocPar")
    parRng.Move Unit:=wdParagraph, Count:=1
parRng.Select
parRng.Style = ActiveDocument.Styles("Title") 'this should be in italics (but fails)
---------------
'Formatting unnumbered subtitles
    For Each Paragraph In ActiveDocument.Paragraphs
    NrPar = NrPar + 1
If Paragraph.Range.ComputeStatistics(wdStatisticLines) = 1 _
And Paragraph.Range.ParagraphFormat.Alignment = wdAlignParagraphLeft _
And Not Paragraph.Range Like "*[0-9]*" Then
ActiveDocument.Paragraphs(NrPar).Range.Select
Selection.ClearFormatting 'apparently necessary
Selection.Style = ActiveDocument.Styles("NotNrPar") 'this should be in italics (OK)
End If
    Next Paragraph
NrPar = 0
Reply With Quote