Microsoft Office Forums

Go Back   Microsoft Office Forums > Microsoft Word > Word VBA

Reply
 
LinkBack Thread Tools Display Modes
  #1  
Old 07-17-2013, 12:22 PM
flatop flatop is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jul 2013
Posts: 5
flatop is on a distinguished road
Unhappy 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
Hello,

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
Reply With Quote
  #2  
Old 09-28-2013, 01:30 AM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,309
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

I've been OS for 3 months, hence the delay in replying. Have you resolved the issue, or do you still need help?
Quote:
is it possible to get this macro to work for Outlook 2010 or I should say the same concept?
The macro probably won't work in Outlook, as it uses Word's built-in wildcard Find/Replace expressions. The same concept, using the RegEx library, should work in Outlook. I'm not proficient with RegEx, though.
__________________
Cheers,
Paul Edstein
[MS MVP - Word]
Reply With Quote
  #3  
Old 04-16-2014, 09:34 PM
flatop flatop is offline Windows 7 64bit Office 2010 64bit
Novice
 
Join Date: Jul 2013
Posts: 5
flatop is on a distinguished road
Default

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.
Reply With Quote
  #4  
Old 04-16-2014, 10:29 PM
macropod's Avatar
macropod macropod is offline Windows 7 32bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 16,309
macropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to beholdmacropod is a splendid one to behold
Default

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
[MS MVP - Word]
Reply With Quote
Reply
Please reply to this thread with any new information or opinions.

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and highlight multiple words in MS Word document AtaLoss Word VBA 33 10-10-2017 01:35 AM
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


All times are GMT -7. The time now is 06:54 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
MSOfficeForums.com is not affiliated with Microsoft