#1
|
|||
|
|||
Find and highlight multiple words in a document
Code:
Sub HiLightList() Application.ScreenUpdating = False Dim StrFnd As String, Rng As Range, i As Long StrFnd = "dog,cat,pig,horse,man" For i = 0 To UBound(Split(StrFnd, ",")) Set Rng = ActiveDocument.Range With Rng.Find .ClearFormatting .Text = Split(StrFnd, ",")(i) .Replacement.ClearFormatting .Replacement.Highlight = True .Replacement.Text = "^&" .Forward = True .Wrap = wdFindContinue .Format = True .MatchCase = False .MatchWholeWord = True .MatchWildcards = False .MatchSoundsLike = False .MatchAllWordForms = True .Execute Replace:=wdReplaceAll End With Next Set Rng = Nothing Application.ScreenUpdating = True End Sub is it possible to get this macro to work for Outlook 2010 or I should say the same concept? Last edited by flatop; 07-17-2013 at 12:30 PM. Reason: Clarification |
#2
|
||||
|
||||
I've been OS for 3½ months, hence the delay in replying. Have you resolved the issue, or do you still need help?
Quote:
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
|||
|
|||
Hello Paul, my apologies for not replying sooner. We had a little one born last September and I haven't had much time since. I have been using the script in Word that you posted earlier. It works well except that having to copy into Word and then cutting and pasting it into a new Outlook post is an added step. One of my co-workers asked why it wouldn't work in Outlook, which I tried to explain to him that the programs are not the same. Any how, I see that you stated you are not proficient with RegEx, do you know of anyone on this forum that is? I will see if I can do some searching and reading to see if I can come up with something on using the RegEx library. Thanks again for responding.
|
#4
|
||||
|
||||
Actually, I probably mis-read which set of code you were referring to. The macro quoted in your post doesn't use wildcards, so that aspect of the issue doesn't apply. Even so, the code is Word-specific and would require some changes before it could be used (if at all) in Outlook.
Outlook doesn't work with Word's Document or Range metaphors, so you'd have to change those aspects, presumably to work with a specified email (the outlook equivalent of a Word document) and it's body text (the Outlook equivalent of a Word range). On top of that, whatever Find/Replace code you use would have to be tailored to Outlook's VBA methods & properties (see http://msdn.microsoft.com/en-us/library/ee814736.aspx). If you take the Word code you're using and ask a question in our Outlook forum as to how to adapt it for use with whatever it is you're trying to highlight, someone there might be able to help you.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Find and highlight multiple words in MS Word document | AtaLoss | Word VBA | 37 | 09-22-2021 12:04 PM |
Help with finding multiple keywords in a single document then highlight | navyguy | Word | 2 | 01-03-2014 12:48 PM |
Highlight and then replace multiple words | redhin | Word VBA | 5 | 03-05-2013 05:42 AM |
Find and highlight all words ending in -ly | RBLampert | Word VBA | 13 | 10-23-2012 04:45 PM |
find - reading highlight - highlight all / highlight doesn't stick when saved | bobk544 | Word | 3 | 04-15-2009 03:31 PM |