Reply
 
Thread Tools Display Modes
  #1   Report Post  
Posted to microsoft.public.word.docmanagement
GottaRun GottaRun is offline
external usenet poster
 
Posts: 1
Default replacing text with open/closing text marks or brackets

Hi,

I have a list of text.
If a text contains an @ I want to enclosed that text with . Example:
replace with

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!

--
Lets Roll
-W
  #2   Report Post  
Posted to microsoft.public.word.docmanagement
Graham Mayor Graham Mayor is offline
external usenet poster
 
Posts: 19,312
Default replacing text with open/closing text marks or brackets

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
Word MVP web site http://word.mvps.org


GottaRun wrote:
Hi,

I have a list of text.
If a text contains an @ I want to enclosed that text with . Example:
replace with

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!



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Find and Replace blocks of text within brackets Archangel Microsoft Word Help 3 May 9th 23 02:47 AM
word 2002- replacing highlighted text with new text Michael[_2_] Microsoft Word Help 1 April 10th 07 02:57 AM
Appearance of square brackets within text Nick New Users 8 November 13th 06 10:51 PM
Replacing text, instead of replacing, text inserts alongside word Margaret Minker Microsoft Word Help 4 December 9th 05 03:52 PM
replacing text ciwrites Microsoft Word Help 1 May 7th 05 06:58 PM


All times are GMT +1. The time now is 02:31 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"