replacing text with open/closing text marks or brackets

  • Thread starter Thread starter GottaRun
  • Start date Start date
G

GottaRun

Hi,

I have a list of text.
If a text contains an @ I want to enclosed that text with <>. Example:
(e-mail address removed) replace with <[email protected]>

If a text contains a space, I want to enclosed that text with ". Example:
John & Jane Smith -> "John & Jane Smith"

I looked at "Find|Replace" with wildcards but did not find the right trick.

Please help.

Thanks!
 
If this is a list of texts one per paragraph then the following macro will
add the extra characters as required

With Selection
.WholeStory
.ConvertToTable Separator:=wdSeparateByParagraphs, NumColumns:=1
.HomeKey Unit:=wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = "<*\@*.*>"
.Replacement.Text = "<^&>"
.Forward = True
.Wrap = wdFindContinue
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = True
'.Execute
.Execute replace:=wdReplaceAll
.Text = "<[a-zA-Z ]{2,}&[a-zA-Z ]{2,}>"
.Replacement.Text = """^&"""
.Execute
.Execute replace:=wdReplaceAll
End With
.Tables(1).Select
.Rows.ConvertToText Separator:=wdSeparateByParagraphs
End With

http://www.gmayor.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top