View Single Post
 
Old 11-22-2022, 10:24 AM
Mehermon Mehermon is offline Windows 10 Office 2021
Novice
 
Join Date: Nov 2022
Posts: 4
Mehermon is on a distinguished road
Default Word VBA find over 50 words/phrases and verify they are underlined.

Hello

I have uploaded my document. The VBA code that I have come up with currently is this:

Sub Underline()

'Declare our variables
Dim wrdFind As Find
Dim wrdRng As Range
Dim wrdDoc As Document

'Grab the active Document
Set wrdDoc = Application.ActiveDocument

'define content in this document
Set wrdRng = wrdDoc.Content

'Define the Find Object based on the range
Set wrdFind = wrdRng.Find

'Define the parameters of our serch
With wrdFind

'look for phrase
.Text = "HabilitationServices"

'verify the phrase is underlined
.MatchCase = False
.MatchPhrase = False
.MatchWholeWord = True
.Font.Underline = False
.MatchAllWordForms = True
.IgnoreSpace = True
.IgnorePunct = True


'Conduct the search if a match it returns TRUE else False
SearchResult = .Execute

End With

'In this case find Every instance.

Do While wrdFind.Execute = True

Loop

'If we found it, display it.

If SearchResult = True Then


'Change the word to be highlighted
wrdRng.HighlightColorIndex = wdRed



End If


End Sub

I am having issues with looping. It doesn't appear to be looping correctly as it only finds the phrase/word once and highlights it if it is not underlined.

I also have attached the document Underline Review. This document has a list of all the words/phrases I need to search the document for and verify they are underlined. Is there an easy way to list all of them out on my visual basic?

Any help is appreciated. I have come up with the above code so far by just using google.

Thank you
Megan Hermon
Reply With Quote