B
BHW
I have a little macro that finds long sentences in my entire document
and highlights the first word of each long sentence. Generally I will
fix the offending sentence, but it still might be too long. I'd like a
macro that checks each sentence in the paragraph containing the
offending sentence and removes highlighting (if necessary). Here's
what I have so far.
For the entire document:
Sub longsent()
Dim item As Range
For Each item In ActiveDocument.Sentences
'item.Select
If item.Words.Count > 40 Then
item.Words.First.HighlightColorIndex = wdYellow
'MsgBox ("Num words = " & item.Words.Count)
End If
Next item
End Sub
this works for individual sentences, where I have the cursor inside of
the sentence.
Sub testsent()
Selection.Range.Sentences.First.Select
Selection.Words.First.HighlightColorIndex = wdNoHighlight
If Selection.Words.Count > 40 Then
MsgBox ("still long " & Selection.Words.Count & " words")
Selection.Words.First.HighlightColorIndex = wdYellow
End If
Selection.Range.Sentences.First.Select
rem try to deselect sentence - doesn't work
End Sub
Thanks!
and highlights the first word of each long sentence. Generally I will
fix the offending sentence, but it still might be too long. I'd like a
macro that checks each sentence in the paragraph containing the
offending sentence and removes highlighting (if necessary). Here's
what I have so far.
For the entire document:
Sub longsent()
Dim item As Range
For Each item In ActiveDocument.Sentences
'item.Select
If item.Words.Count > 40 Then
item.Words.First.HighlightColorIndex = wdYellow
'MsgBox ("Num words = " & item.Words.Count)
End If
Next item
End Sub
this works for individual sentences, where I have the cursor inside of
the sentence.
Sub testsent()
Selection.Range.Sentences.First.Select
Selection.Words.First.HighlightColorIndex = wdNoHighlight
If Selection.Words.Count > 40 Then
MsgBox ("still long " & Selection.Words.Count & " words")
Selection.Words.First.HighlightColorIndex = wdYellow
End If
Selection.Range.Sentences.First.Select
rem try to deselect sentence - doesn't work
End Sub
Thanks!