From: Janet S on
I'm working on a sub to (1) search for a particular style, (2) move to the
preceding paragraph, (3) check what style it is, and (4) if it's the style
"Heading 2", move back to the following paragraph and do something. It's step
3 that's giving me trouble. How do I say: if the paragraph has a particular
style...
This is what I've got, but it doesn't work.
If .Style = wdStyleHeading2 Then
Thank you in advance,
~ Janet
From: Doug Robbins - Word MVP on
Hi Janet,

Use:

Dim prange As Range
Dim i As Long
Selection.HomeKey wdStory
Selection.Find.ClearFormatting
Selection.Find.Style = ActiveDocument.Styles("List Paragraph")
With Selection.Find
Do While .Execute(FindText:="", Forward:=True, _
MatchWildcards:=False, _
Wrap:=wdFindStop, MatchCase:=False) = True
Set prange = ActiveDocument.Range
prange.End = Selection.Range.End
Set prange = prange.Paragraphs(prange.Paragraphs.Count -
1).Range
If prange.Paragraphs(1).Style = "Heading 2" Then
Exit Sub
Else
Selection.Collapse wdCollapseEnd
End If
Loop
End With


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"Janet S" <JanetS(a)discussions.microsoft.com> wrote in message
news:FDDDA1F4-4214-4965-9883-17892A18B6F8(a)microsoft.com...
> I'm working on a sub to (1) search for a particular style, (2) move to the
> preceding paragraph, (3) check what style it is, and (4) if it's the style
> "Heading 2", move back to the following paragraph and do something. It's
> step
> 3 that's giving me trouble. How do I say: if the paragraph has a
> particular
> style...
> This is what I've got, but it doesn't work.
> If .Style = wdStyleHeading2 Then
> Thank you in advance,
> ~ Janet