Find more than one style at once?

H

Harry Bronfield

This is not possible, right? It sure would be useful to be able to
tell Word "Find style A or style B".
 
G

Greg Maxey

This is not possible, right? It sure would be useful to be able to
tell Word "Find style A or style B".

Depends on how you go about finding it. You can't use the standard
Find and Replace methods, but you can look at each paragraph
individually to determine if it is formatted with style A or B and
then proceed accordingly:

Sub ScracthMacro()
Dim aPar As Paragraph
For Each aPar In ActiveDocument.Paragraphs
Select Case aPar.Style
Case Is = "Stlye A", "Stlye B"
aPar.Style = "Style C"
Case Else
End Select
Next
End Sub
 
S

Stefan Blom

Just out of curiosity, do you know if one method would be quicker than the
other?

--
Stefan Blom
Microsoft Word MVP



This is not possible, right? It sure would be useful to be able to
tell Word "Find style A or style B".

Depends on how you go about finding it. You can't use the standard
Find and Replace methods, but you can look at each paragraph
individually to determine if it is formatted with style A or B and
then proceed accordingly:

Sub ScracthMacro()
Dim aPar As Paragraph
For Each aPar In ActiveDocument.Paragraphs
Select Case aPar.Style
Case Is = "Stlye A", "Stlye B"
aPar.Style = "Style C"
Case Else
End Select
Next
End Sub
 
G

Greg Maxey

Stefan,

No I don't and there is probably little to be gained or lost wrt to speed
using a method like this. The only real advantage that I could see is if a
user needed to find the first instance of A or B.

Sub ScracthMacro()
Dim aPar As Paragraph
For Each aPar In ActiveDocument.Paragraphs
Select Case aPar.Style
Case Is = "Stlye A", "Stlye B"
If aPar.Style = "Style A" Then
'Do this
Exit Sub
Else
'Do that
Exit Sub
Case Else
End Select
Next
End Sub
 

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