G
Greg Maxey
I just spent 45 minutes trying to put together a Select Case statement. I
have something that works, but I really don't think that I am employing this
method like it is supposed to be used.
The object is to look at individual paragraphs and apply a style if the
opening words match a string. Example:
Match this text blah, blah, blah
No matching text blah, blah, blah
Match this text blah, blah, blah
Match some other text blah, blah, blah
I want "Match this text" lines Heading 1
I want "Match some other text" lines Heading 2
Here is my code:
Sub Test()
Dim oPar As Paragraph
Dim Match As Boolean
Match = True
For Each oPar In ActiveDocument.Paragraphs
Select Case Match
Case InStr(oPar.Range.Text, "Match this text") = 1
oPar.Style = "Heading 1"
Case InStr(oPar.Range.Text, "Match some other text") = 1
oPar.Style = "Heading 2"
End Select
Next oPar
End Sub
OK it is doing the intended but I nearly cracked my skull trying to figure
it out. Am I doing this right? Thanks.
have something that works, but I really don't think that I am employing this
method like it is supposed to be used.
The object is to look at individual paragraphs and apply a style if the
opening words match a string. Example:
Match this text blah, blah, blah
No matching text blah, blah, blah
Match this text blah, blah, blah
Match some other text blah, blah, blah
I want "Match this text" lines Heading 1
I want "Match some other text" lines Heading 2
Here is my code:
Sub Test()
Dim oPar As Paragraph
Dim Match As Boolean
Match = True
For Each oPar In ActiveDocument.Paragraphs
Select Case Match
Case InStr(oPar.Range.Text, "Match this text") = 1
oPar.Style = "Heading 1"
Case InStr(oPar.Range.Text, "Match some other text") = 1
oPar.Style = "Heading 2"
End Select
Next oPar
End Sub
OK it is doing the intended but I nearly cracked my skull trying to figure
it out. Am I doing this right? Thanks.