Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 11-08-2023, 09:58 AM
RobiNew RobiNew is offline Formatting specific paragraphs with styles without using Selection Windows 10 Formatting specific paragraphs with styles without using Selection Office 2016
Competent Performer
Formatting specific paragraphs with styles without using Selection
 
Join Date: Sep 2023
Posts: 200
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Formatting specific paragraphs with styles without using Selection Assign different heading styles for different paragraphs Thorin23 Word VBA 3 05-02-2021 06:22 AM
Formatting all paragraphs based on pre defined styles afif Word VBA 0 07-26-2019 06:18 AM
Formatting specific paragraphs with styles without using Selection Make paragraphs appear according to specific combination razdul Word VBA 2 04-17-2019 06:17 AM
Trouble Formatting Specific Paragraphs - Bullets, Spacing, Centering, etc adzialo Word 2 05-01-2017 12:53 PM
Formatting specific paragraphs with styles without using Selection Selection of all Text for a specific page in word is spanning selection across pages ramsgarla Word VBA 9 12-05-2012 03:23 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:16 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