Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 11-22-2022, 10:24 AM
Mehermon Mehermon is offline Word VBA find over 50 words/phrases and verify they are underlined. Windows 10 Word VBA find over 50 words/phrases and verify they are underlined. Office 2021
Novice
Word VBA find over 50 words/phrases and verify they are underlined.
 
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
  #2  
Old 11-22-2022, 01:16 PM
macropod's Avatar
macropod macropod is offline Word VBA find over 50 words/phrases and verify they are underlined. Windows 10 Word VBA find over 50 words/phrases and verify they are underlined. Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Is there a reason for highlighting the words instead of just underlining them?
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #3  
Old 11-22-2022, 01:41 PM
Mehermon Mehermon is offline Word VBA find over 50 words/phrases and verify they are underlined. Windows 10 Word VBA find over 50 words/phrases and verify they are underlined. Office 2021
Novice
Word VBA find over 50 words/phrases and verify they are underlined.
 
Join Date: Nov 2022
Posts: 4
Mehermon is on a distinguished road
Default

This review is part of an audit. If the word is not underlined, we need to have it highlighted so that we can point the error out for a different user to fix.
Reply With Quote
  #4  
Old 11-23-2022, 05:26 AM
macropod's Avatar
macropod macropod is offline Word VBA find over 50 words/phrases and verify they are underlined. Windows 10 Word VBA find over 50 words/phrases and verify they are underlined. Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

To just do the highlighting, see, for example: https://www.msofficeforums.com/118565-post30.html
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #5  
Old 11-23-2022, 06:35 AM
Mehermon Mehermon is offline Word VBA find over 50 words/phrases and verify they are underlined. Windows 10 Word VBA find over 50 words/phrases and verify they are underlined. Office 2021
Novice
Word VBA find over 50 words/phrases and verify they are underlined.
 
Join Date: Nov 2022
Posts: 4
Mehermon is on a distinguished road
Default

Thank you for the information. I will check it out.
Reply With Quote
  #6  
Old 11-23-2022, 08:10 AM
Mehermon Mehermon is offline Word VBA find over 50 words/phrases and verify they are underlined. Windows 10 Word VBA find over 50 words/phrases and verify they are underlined. Office 2021
Novice
Word VBA find over 50 words/phrases and verify they are underlined.
 
Join Date: Nov 2022
Posts: 4
Mehermon is on a distinguished road
Default

Thank you so much! This works well; however, I do have a few phrases such as out-of-network provider where it is only reading "provider" and highlighting it if it is not underlined. I have tried to insert ignore spacing and ignore punctuation but it still isn't reading correctly. Is there an easy solution to this?
Reply With Quote
  #7  
Old 11-23-2022, 02:12 PM
macropod's Avatar
macropod macropod is offline Word VBA find over 50 words/phrases and verify they are underlined. Windows 10 Word VBA find over 50 words/phrases and verify they are underlined. Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Do not the code there uses:
.MatchCase =True
which means it will only find strings where the case in the text is what you're supplying in code. You could change it to:
.MatchCase = False
but you might then be doing some unintended highlighting (or maybe you'll catch some that would outherwise be missed).
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #8  
Old 11-23-2022, 02:21 PM
Guessed's Avatar
Guessed Guessed is offline Word VBA find over 50 words/phrases and verify they are underlined. Windows 10 Word VBA find over 50 words/phrases and verify they are underlined. Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,932
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

If your find string is more than one word (includes a space) then this setting might also be a problem
.MatchWholeWord = True
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #9  
Old 11-23-2022, 03:01 PM
macropod's Avatar
macropod macropod is offline Word VBA find over 50 words/phrases and verify they are underlined. Windows 10 Word VBA find over 50 words/phrases and verify they are underlined. Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,956
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Word automatically disables that when the Find string contains more than one word.

More likely to cause problems is:
.MatchAllWordForms = True
That can only be used with single words. In any event, it should probably be:
.MatchAllWordForms = False
for the OP's purposes with single words also.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word VBA find over 50 words/phrases and verify they are underlined. VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters Kalü Word VBA 22 04-24-2018 05:35 AM
Word VBA find over 50 words/phrases and verify they are underlined. How to mark underlined words in a sentence as A, B, C, D (beneath the words) thudangky Word 13 12-12-2013 02:22 AM
How do I find Repeating Words/Phrases? CCD2016 PowerPoint 0 12-01-2013 09:37 PM
Word VBA find over 50 words/phrases and verify they are underlined. Almost all words underlined by Word. Wim vd Velden Word 1 10-02-2012 05:57 AM
Transferring all the underlined words swemhsut Word 0 08-20-2010 01:34 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:15 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft