![]() |
|
#1
|
|||
|
|||
|
Hi All,
I need a help to complete my code and make it live. Please help me to create an input box where the user has to insert the list of words with out going to the code. Here the word list is ("Friend", "MITS", "ICMR"). Note that the list of words varies from document to document. Below is the code. Sub FindHighlightWord() Dim oRng As Word.Range Dim arrWords Dim i As Long Options.DefaultHighlightColorIndex = wdGreen arrWords = Array("Friend", "MITS", "ICMR") For i = 0 To UBound(arrWords) Set oRng = ActiveDocument.Range With oRng.Find .ClearFormatting .Replacement.ClearFormatting .Replacement.Highlight = True .Text = arrWords(i) .MatchWholeWord = True .Execute Replace:=wdReplaceAll End With Next End Sub Many thanks for your help. Regards, Raj |
|
#2
|
||||
|
||||
|
How about
Code:
Sub FindHighlightWord()
Dim oRng As Word.Range
Dim vWords As Variant
Dim i As Long
Dim strWords As String
strWords = InputBox(Prompt:="Enter the words to highlight separated by commas", _
Title:="Highlight words", _
Default:="Friend,MITS,ICMR")
vWords = Split(strWords, ",")
For i = 0 To UBound(vWords)
Set oRng = ActiveDocument.Range
With oRng.Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(FindText:=Trim(vWords(i)), _
MatchWholeWord:=True) = True
oRng.HighlightColorIndex = wdBrightGreen
oRng.Collapse 0
Loop
End With
Next
lbl_Exit:
Set oRng = Nothing
Exit Sub
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019) Visit my web site for more programming tips and ready made processes www.gmayor.com |
|
#3
|
|||
|
|||
|
Thanks GMAYOR for your help :-)
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Mail merge from excel - need to create sheets and create a table
|
bluenosebex | Mail Merge | 5 | 08-02-2015 05:34 PM |
| Variable arrays from user input | SeattleITguy | Excel Programming | 1 | 01-29-2015 09:19 AM |
Searching Arrays without Loops?
|
ptmuldoon | Word VBA | 3 | 12-13-2014 11:21 AM |
Input Box
|
ubns | Word | 2 | 04-13-2012 06:28 AM |
re-naming arrays in VBA?
|
JDevsFan | Excel Programming | 4 | 03-15-2012 08:44 AM |