Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-13-2023, 01:27 AM
RobiNew RobiNew is offline Format paragraphs between Start and End Windows 10 Format paragraphs between Start and End Office 2016
Competent Performer
Format paragraphs between Start and End
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default Format paragraphs between Start and End


I'm trying to format paragraphs between Start and End, but my code fails. Can someone help? Thanks!
Code:
Sub StartEnd()
'Format paragraphs between Start and End
   Dim oRng As Range
  Set oRng = ActiveDocument.Range(Start:=64, End:=ActiveDocument.Paragraphs.Count)
    With oRng.Paragraphs
    For Each oPar In oRng.Paragraphs
              oPar.Style = "MyStyle"
    Next oPar
    End With
End Sub
Reply With Quote
  #2  
Old 11-13-2023, 01:56 AM
gmayor's Avatar
gmayor gmayor is offline Format paragraphs between Start and End Windows 10 Format paragraphs between Start and End Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,106
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Define the range, then format the range e.g.
Code:
Sub StartEnd()
'Format paragraphs between Start and End
Dim oRng As Range
  Set oRng = ActiveDocument.Range
    oRng.Start = ActiveDocument.Range.Paragraphs(3).Range.Start
    oRng.End = ActiveDocument.Range.End
    oRng.Style = "MyStyle"
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #3  
Old 11-13-2023, 10:51 AM
RobiNew RobiNew is offline Format paragraphs between Start and End Windows 10 Format paragraphs between Start and End Office 2016
Competent Performer
Format paragraphs between Start and End
 
Join Date: Sep 2023
Posts: 183
RobiNew is on a distinguished road
Default

Perfect. Thanks a lot, Gmayor!
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Lock Format Changed Paragraphs From Style Modifications EdA SRQ Word 3 03-12-2022 09:35 PM
Format paragraphs between Start and End How to duplicate paragraphs & format them effimera Word VBA 2 12-20-2021 04:40 AM
Format paragraphs between Start and End Format multiple paragraphs differently Dave T Word VBA 7 07-31-2019 08:12 PM
Changing the format/style for numbered paragraphs AND MAKING THEM STICK! FearlessStamper Word 2 10-30-2017 02:17 PM
Format paragraphs between Start and End VBA to set format for paragraphs that meet with specific requirements AustinBrister Word VBA 3 06-01-2015 07:00 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 07:02 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft