Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-14-2021, 03:58 AM
TheBigBoss TheBigBoss is offline Range - Start at beginning of doc - End at defined stylename Windows 7 32bit Range - Start at beginning of doc - End at defined stylename Office 2010 32bit
Advanced Beginner
Range - Start at beginning of doc - End at defined stylename
 
Join Date: Dec 2016
Posts: 56
TheBigBoss is on a distinguished road
Default Range - Start at beginning of doc - End at defined stylename

Hi there,

It is possible to select a range that:
- Start at beginning of document
- End at a paragraph with a defined stylename



Thanks for the help
Reply With Quote
  #2  
Old 10-14-2021, 02:46 PM
Guessed's Avatar
Guessed Guessed is offline Range - Start at beginning of doc - End at defined stylename Windows 10 Range - Start at beginning of doc - End at defined stylename Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,969
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

This should work
Code:
Sub Find2Style()
  Dim aRng As Range
  Set aRng = ActiveDocument.Range
  With aRng.Find
    .Text = ""
    .Replacement.Text = ""
    .ClearFormatting
    .Style = ActiveDocument.Styles("Heading 2")
    .Forward = True
    .Wrap = wdFindStop
    .Format = True
    .MatchCase = False
    If .Execute Then
      aRng.Start = 0
      aRng.Select
    Else
      MsgBox "Style not found"
    End If
  End With
End Sub
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 10-18-2021, 07:27 AM
TheBigBoss TheBigBoss is offline Range - Start at beginning of doc - End at defined stylename Windows 7 32bit Range - Start at beginning of doc - End at defined stylename Office 2010 32bit
Advanced Beginner
Range - Start at beginning of doc - End at defined stylename
 
Join Date: Dec 2016
Posts: 56
TheBigBoss is on a distinguished road
Default

Hi there,

It does the job, thank you very much
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
Range - Start at beginning of doc - End at defined stylename Start find macro beginning with section 2 jeffreybrown Word VBA 3 09-21-2018 04:01 PM
How to get start and end range indices of a selection paik1002 Word VBA 7 07-02-2017 10:44 PM
Dymanic Range Starting at a Cell Defined by a Count jap7675 Excel Programming 7 12-02-2015 02:12 AM
Range - Start at beginning of doc - End at defined stylename Data validation list filter with range defined by OFFSET Mango123 Excel 4 03-18-2014 02:52 PM
Range - Start at beginning of doc - End at defined stylename Range.Information(wdStartOfRangeRowNumber): Application-defined or Object-defined err tinfanide Excel Programming 2 06-09-2012 10:19 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:24 PM.


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