#1
|
|||
|
|||
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 |
#2
|
||||
|
||||
Is there a reason for highlighting the words instead of just underlining them?
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
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.
|
#4
|
||||
|
||||
To just do the highlighting, see, for example: https://www.msofficeforums.com/118565-post30.html
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#5
|
|||
|
|||
Thank you for the information. I will check it out.
|
#6
|
|||
|
|||
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?
|
#7
|
||||
|
||||
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] |
#8
|
||||
|
||||
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 |
#9
|
||||
|
||||
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] |
Thread Tools | |
Display Modes | |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
VBA Find&Replace all bold, itlaic, underlined and highlighted words/characters | Kalü | Word VBA | 22 | 04-24-2018 05:35 AM |
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 |
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 |