Reputation: 69
I want to mark, in red, the paragraph which begins with "proof of theorem".
My code is below:
Sub theorem()
Dim p As Paragraph, d As Document
For Each p In ActiveDocument
If p.Range.Words(1) = "Proof " And p.range.words(2) = "of " and p.Range.Words(3) = "theorem " Then
End If
End Sub
I feel this method “If p.Range.Words(1) = "Proof " And p.range.words(2) = "of " and p.Range.Words(3) = "theorem "
” is bulky. I would like to ask whether there is a more concise method, or any other tips.
Upvotes: 0
Views: 30
Reputation: 23994
You could just use the Left
function to retrieve the first 16 characters of the paragraph and test that:
Sub theorem()
Dim p As Paragraph, d As Document
For Each p In ActiveDocument.Paragraphs
If Left(p.Range.Text, 16) = "Proof of theorem" Then
p.Range.Font.ColorIndex = wdRed
End If
Next
End Sub
Upvotes: 1