![]() |
|
|||||||
|
|
|
Thread Tools | Display Modes |
|
#1
|
|||
|
|||
|
Hey.
Ok, I want to do something which to me seems pretty straight forward but I can't think how to do it. In a body of text I have managed to find and use a vb macro script which will select and highlight multiple words. e.g. I can tell it to find "yellow,green,horse,cat" etc and it will find each of these words separately within the text and highlight them. This is awesome. However, is there a way to get ms word to replace each word I tell it to find, with the same word but with HTML tags either side? e.g. In a body of text, I want it to find every instance of the words "yellow", "green" etc. and replace each "yellow", with "<command>yellow</command>" and each "green" with "<command>green</command>". Is it possible to do this in one go if you tell it which words to look for, or would this be an operation I need to do separately for each different word? I ask because I need to find about 200 separate words in a large body of text and have each word basically wrapped in one specific HTML tag. Seems simple enough if it was only one word I needed to find but multiple words make it more complicated. Thanks for any help guys, its much appreciated! |
|
#2
|
||||
|
||||
|
If you provide at least a link to the macro to which you refer (better still, post a formatted copy - using code tags), someone might be able to tell you how you could modify it. It's probably a simple modification, but no-one can say exactly what to change without seeing the code.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#3
|
|||
|
|||
|
Sure,
This is the macro code I am using to highlight each separate word. Its a very lightly modified code I found on these forums. Code:
Sub HiLightList()
Application.ScreenUpdating = False
Dim StrFnd As String, Rng As Range, i As Long
StrFnd = "yellow,green,dog,horse"
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 = False
.Execute Replace:=wdReplaceAll
End With
Next
Set Rng = Nothing
Application.ScreenUpdating = True
End Sub
Thx |
|
#4
|
||||
|
||||
|
You could change:
.Replacement.Text = "^&" to: .Replacement.Text = "<command>^&</command>" Note that, with this approach, the entire replacement string is highlighted.
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
|
#5
|
|||
|
|||
|
Thanks very much Paul. That seems to have worked. A few things I need to iron out, but it works really well.
|
|
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
Highlight and then replace multiple words
|
redhin | Word VBA | 5 | 03-05-2013 05:42 AM |
Create and populate multiple templates with merge tags
|
jelarbey | Word | 1 | 10-09-2012 05:20 AM |
How can I count multiple usage of the same words?
|
coffee_king | Word VBA | 1 | 03-24-2012 07:52 PM |
| Attaching MSG file is stripped on send and HTML tags show on previewing prior to send | Fantastic4 | Outlook | 0 | 01-09-2012 12:18 PM |
Making Multiple Words Bold
|
mtk989 | Word | 2 | 06-25-2011 11:27 AM |