I’m a writer and use VBA to help me clean up my manuscript. I have an adverb search code that works. The code searches my manuscript and highlights every work ending with “ly”.
My problem is that I cannot figure out how to count the number of words the code highlights.
I would appreciate your help with this.
Thanks,
Amilcar (Aumi) hernandez
Sub Adverbs()
Application.ScreenUpdating = False
Dim i As Integer
Dim cnt As Integer
Dim color As Integer
Dim msg As String
Dim slist As String
Dim title As String
Dim hilite As String
Dim rng As range
Dim SearchList() As String
'-- User assigned data ------------
slist = "<[! ][! ]@ly>,"
title = "Adverbs"
color = wdBrightGreen
hilite = "Bright-green"
'-- Code assigned variables ------
cnt = 0
SearchList = Split(slist, ",")
Options.DefaultHighlightColorIndex = color
'-- Seach and highlight ------
With ActiveDocument.range.Find
.Text = SearchList(i)
.Forward = True
.MatchWildcards = True
.Replacement.Highlight = True
.Replacement.Text = "^&"
cnt = cnt + 1
.Wrap = wdFindStop
.Format = True
.Execute Replace:=wdReplaceAll
End With
'-- This line of code jumps to the top of the document
Selection.HomeKey Unit:=wdStory
Application.ScreenUpdating = True
'-- Popup mesasge when the macro finishes
msg = "The " & title & " script finished highlighting ->" & cnt & "<- words/phrases in " & hilite & "."
MsgBox msg, vbInformation
End Sub
New contributor
Amilcar Hernandez is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.