Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 06-05-2013, 06:43 AM
String String is offline Trying to wrap HTML tags around multiple different words in one operation Windows XP Trying to wrap HTML tags around multiple different words in one operation Office 2007
Novice
Trying to wrap HTML tags around multiple different words in one operation
 
Join Date: Jun 2013
Posts: 3
String is on a distinguished road
Default Trying to wrap HTML tags around multiple different words in one operation

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!
Reply With Quote
  #2  
Old 06-05-2013, 07:36 AM
macropod's Avatar
macropod macropod is offline Trying to wrap HTML tags around multiple different words in one operation Windows 7 32bit Trying to wrap HTML tags around multiple different words in one operation Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,954
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #3  
Old 06-05-2013, 07:44 AM
String String is offline Trying to wrap HTML tags around multiple different words in one operation Windows XP Trying to wrap HTML tags around multiple different words in one operation Office 2007
Novice
Trying to wrap HTML tags around multiple different words in one operation
 
Join Date: Jun 2013
Posts: 3
String is on a distinguished road
Default

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
So once its found and highlighted these words, I need it to wrap an HTML tag around them all.

Thx
Reply With Quote
  #4  
Old 06-05-2013, 03:34 PM
macropod's Avatar
macropod macropod is offline Trying to wrap HTML tags around multiple different words in one operation Windows 7 32bit Trying to wrap HTML tags around multiple different words in one operation Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,954
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

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]
Reply With Quote
  #5  
Old 06-06-2013, 06:23 AM
String String is offline Trying to wrap HTML tags around multiple different words in one operation Windows XP Trying to wrap HTML tags around multiple different words in one operation Office 2007
Novice
Trying to wrap HTML tags around multiple different words in one operation
 
Join Date: Jun 2013
Posts: 3
String is on a distinguished road
Default

Thanks very much Paul. That seems to have worked. A few things I need to iron out, but it works really well.
Reply With Quote
Reply

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Trying to wrap HTML tags around multiple different words in one operation Highlight and then replace multiple words redhin Word VBA 5 03-05-2013 05:42 AM
Trying to wrap HTML tags around multiple different words in one operation Create and populate multiple templates with merge tags jelarbey Word 1 10-09-2012 05:20 AM
Trying to wrap HTML tags around multiple different words in one operation 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
Trying to wrap HTML tags around multiple different words in one operation Making Multiple Words Bold mtk989 Word 2 06-25-2011 11:27 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:26 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2024 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft