automatic replacement of multi-lines text using macro ?

B

bcharloup

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.
 
J

Jay Freedman

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.

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.
 

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

Top