Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2005

Tip: Looking for answers? Try searching our database.

automatic replacement of multi-lines text using macro ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
bcharloup - 10 Nov 2005 00:28 GMT
hi all,
I'am trying to perform in macro automatic search and replace of a text by
another one. The text to be found and replaced is on several lines : I don't
know how to set the .text property of the replacement object to take into
account the text included CR (carriage return or vbCrLf ?).
All the examples in the word documentation show only replacement of "simple"
text, one or more words, but not text on several lines (like a paragraph).
Does anybody can help me ? how to search multi-line text (or expression).
Thanks in advance.


--
Bruno
Jay Freedman - 10 Nov 2005 03:54 GMT
>hi all,
>I'am trying to perform in macro automatic search and replace of a text by
[quoted text clipped - 5 lines]
>Does anybody can help me ? how to search multi-line text (or expression).
>Thanks in advance.

Hi Bruno,

If you're absolutely sure (a) what kind of break ends the lines and
(b) exactly where they are with respect to the visible characters, you
can do this.

A paragraph mark (looks like ¶ when nonprinting characters are
displayed) is represented in the .Text string as vbCr or "^13". A
manual line break (looks like a hooked left-pointing arrow) is
represented as vbVerticalTab or "^11".

For example, if your text looks like this:

  The quick brown fox ¶
  jumped over the lazy dog.

then you can search for

 .Text = "The quick brown fox " & vbCr & "jumped over the lazy dog."

or

 .Text = "The quick brown fox ^11jumped over the lazy dog."

Notice the space after 'fox' in each of these, to match the one in the
text.

You can, of course, put more than one of these together in a single
string.

One other comment: If the text you're searching for is a single
paragraph that's word-wrapped without breaks -- as most paragraphs in
Word are -- then your search string shouldn't contain any break
characters. Just put the words in the .Text string, regardless of how
many lines it appears to cover.

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.