Hi Friends,
I am new to word macros. I have a word document in that need to find a word and highlight that word. Suppose if the word occured 10 times in 10 places the word need to be highlighted. Please give me appropriate code to create a macro.
Thanks & Regards
Ramesh
How about this
Code:Sub HighLight() ' ' enter a search string to be highlighted throughout the document ' ' Dim strWord As String strWord = InputBox("Enter a word", "What do you want to find?") Selection.HomeKey Unit:=wdStory Options.DefaultHighlightColorIndex = wdYellow Selection.Find.ClearFormatting Selection.Find.Replacement.ClearFormatting Selection.Find.Replacement.HighLight = True With Selection.Find .Text = strWord .Replacement.Text = strWord .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = False .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = False .Replacement.HighLight = True End With Selection.Find.Execute Replace:=wdReplaceAll End Sub
teylyn
Microsoft MVP - Excel
At Excelforum, you can say "Thank you!" by clicking theicon below the post.
Avoid pie charts with more than two data points. Why? See here (pdf, 559 kb). The only acceptable pie chart is here.
Hi Teylyn,
Thank you for your reply. It is working in word. Could you please provide the for the same purpose.
What I want in excel is we find a word in entire workbook and need to highlight it.
Please kindly provide the code for excel.
Thanks
Ramesh
In which case post a new question in the Excel Programming Forum.What I want in excel is we find a word in entire workbook and need to highlight it.
Please kindly provide the code for excel.
My Recommended Reading:
Volatility
Sumproduct & Arrays
Pivot Intro
Email from XL - VBA & Outlook VBA
Function Dictionary & Function Translations
Dynamic Named Ranges
Code:Sub myHighLight_TEXT() Dim i As Long Dim myRange As Range Selection.WholeStory i = InStr(Selection, "Microsoft") Selection.Collapse Set myRange = ActiveDocument.Range( _ Start:=ActiveDocument.Characters(i).Start, _ End:=ActiveDocument.Characters(i + 9).End) myRange.HighlightColorIndex = wdYellow Set myRange = Nothing End Sub
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks