if a paragraph has a particular style

J

Janet S

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
 
D

Doug Robbins - Word MVP

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top