PDA

View Full Version : Ignore text if it meets a range of conditions



ashley
10-20-2006, 03:17 PM
I'm trying to write an If-Then-Else statement that applies StyleZ to any text within a selection that is NOT already styled StyleA, StyleB, or StyleC.

I understand If-Then where you want to perform an action (If you find StyleA, Then make the text red), but I don't get the logic behind not doing anything (If you find StyleA, Then ignore it and look for StyleB). :think:

Thanks in advance...
Ashley

fumei
10-22-2006, 04:32 PM
1. Are you sure you want to do this as a Selection? Using Selection is not the best way to process text - but it may be applicable in your case....I don't know.

2. This is straightforward logic issue, and is not difficult. What do you mean by "any" text within a selection. And, what are you currently using now as a chunk of text to test against? A paragraph, a word?

3. Are these styles Paragraph styles, or Character styles?

So it is hard to say, but here is one way you could do it, dealing with PARAGRAPHS.Dim oPara As Word.Paragraph
For Each oPara In Selection.Paragraphs
Select Case oPara.Style
Case "StyleA", "StyleB", "StyleC"
' do nothing
Else
oPara.Style = "StyleZ"
End Select
NextOK, following the logic , if Syle A, B, or C, is found, do nothing...ALL other styles would be changed to Z.

Another way is to expand your If statements to include And, OR statements. Again, you do not state what unit of text you are using to do this.If whateverTEXT unit.Style <> "StyleA" OR _
If whateverTEXT unit.Style <> "StyleB" OR _
If whateverTEXT unit.Style <> "StyleC" Then
whateverTEXT unit.Style = "StyleZ"
End IfSo the text unit would become StyleZ if it was NOT StyleA, or StyleB, or StyleC.