I have a requirement that it should count the no. of words sentence-wise. If no. of words in sentence is more than 20, it should highlight it. & when user closes the Document. This highlighting should be disappeared. Below is the code that i have used. It's counting the no. of words & then highlighting also properly. But, How to un-highlight this when user closes that document?
Sub Count_of_words()
'
' Count Macro
'
'
Dim s As Range
For Each s In Selection.Sentences
If s.Words.count > 20 Then
With s.Font
.Underline = wdUnderlineWavy
.UnderlineColor = wdColorRed
End With
End If
Next
End Sub
You could use Document_Close() event - just put code in it, and it will be executed before document is closed - You could use your original code, but instead of .Underline = wdUnderlineWavy and .UnderlineColor = wdColorRed use values that dont highlight text. Event procedure must be in ThisDocument file, not in module file (You find it in Project Explorer). So, basicly, open ThisDocument and write procedure:
Sub Document_Close()
'
' Count Macro
'
'
Dim s As Range
For Each s In Selection.Sentences
If s.Words.count > 20 Then
With s.Font
.Underline = 'put code to no underline
.UnderlineColor = 'put code to no color
End With
End If
Next
End Sub
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.