
Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
Russ was telling us:
Russ nous racontait que :
> Tllcvg,
>
[quoted text clipped - 27 lines]
> End With
> End Sub
Except that in the case of paragraph styles, the Find only finds one
paragraph at the time. If, for example, 3 contiguous paragraphs are set tot
the same style ("Style1"), .Execute will go to each paragraph one after the
other in three passes through the Loop. The OP wanted to find all paragraphs
that were contiguous in one shot...
While I did not provide a full answer to all of his queries, I did get him
started, but I guess it wasn't important since we haven't heard from him!

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Russ - 15 Oct 2006 08:51 GMT
Jean-Guy,
You're right I didn't use aRange.select to test my sub. It just appeared to
do it all at once. :(
I only had in the back of my mind that your sub was iterating through
paragraphs and what if the OP didn't mean whole paragraphs?, then the find
would be faster and offer another solution. His post skirts around and
doesn't use the word 'paragraph'; with phrases like "section","lines", and
"body of text". But I guess the majority of time, when someone uses a style,
it is a paragraph style, encompassing all lines in the paragraph.
> Russ was telling us:
> Russ nous racontait que :
[quoted text clipped - 39 lines]
> While I did not provide a full answer to all of his queries, I did get him
> started, but I guess it wasn't important since we haven't heard from him!

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID
Russ - 15 Oct 2006 22:09 GMT
Tllcvg,
The revised subroutine below now appears to select contiguous style whether
it is a character style or paragraph style.
VBA Help says that when reading the style of an range like a word or
sentence, the match will only be with the first style used in that range and
it doesn't return a position of where that first style is used. So there was
no quick way to tell if the whole word or whole sentence was that style.
Therefore I wasn't able to use words and sentences to speed up the
subroutine.
Sub ManipulateStyleRange()
Dim aRange As Range
Dim aDoc As Document
Dim myStyle As String
Set aRange = ActiveDocument.Range(0, 0)
Set aDoc = ActiveDocument
myStyle = "Style1"
With aRange.Find
.Style = aDoc.Styles(myStyle)
While .Execute
While aRange.Paragraphs.Last.Next.Style = aDoc.Styles(myStyle)
aRange.MoveEnd unit:=wdParagraph
Wend
While aRange.Characters.Last.Next.Style = aDoc.Styles(myStyle)
aRange.MoveEnd unit:=wdCharacter
Wend
aRange.Select ' put your code here to alter aRange
aRange.Start = aRange.End 'needed to avoid endless looping
Wend
End With
End Sub
> Jean-Guy,
> You're right I didn't use aRange.select to test my sub. It just appeared to
[quoted text clipped - 49 lines]
>> While I did not provide a full answer to all of his queries, I did get him
>> started, but I guess it wasn't important since we haven't heard from him!

Signature
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID