Macro find and replace, but also keep certain things

FrecklePaw
2StarLounger
Posts: 130
Joined: 12 Aug 2020, 08:40

Macro find and replace, but also keep certain things

Post by FrecklePaw »

I wasn't sure how to title this one, sorry if it's not very clear.

But what I want to do... I have macro code for 'find and replace' with the FromArray, ToArray code.

I have instructions set up within the macro so that whenever it comes across a particular word, e.g. ‘current’, it will replace it with a new line (i.e. using "^p^p")

But instead of replacing it, how can I set up an instruction (preferably within the same macro) that instead of replacing it with the new line ("^p^p") it will KEEP that word (e.g. current) AND create a new line?

User avatar
HansV
Administrator
Posts: 78545
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Macro find and replace, but also keep certain things

Post by HansV »

You can use ^& to refer to the 'find what' text, whatever that was. So "^&^p^p" as Replacement.Text will cause the 'find text' to be replaced with the 'find text' followed by 2 paragraph breaks.

By the way, it is better not to use two paragraph breaks in a row. Instead, increase the space before and/or space after setting of the paragraph style.
Two paragraph breaks in a row may cause an empty paragraph at the top of a page:

S2065.png

After adding some text to the upper page:

S2066.png
You do not have the required permissions to view the files attached to this post.
Best wishes,
Hans

FrecklePaw
2StarLounger
Posts: 130
Joined: 12 Aug 2020, 08:40

Re: Macro find and replace, but also keep certain things

Post by FrecklePaw »

amazing, thank you!