Reworking the Delete ^p^p function

All I wanted to do was to update this function to work with a selection (i.e. user has made a selection of text, which included a few multiples of ^p in it) and the search & replace would then only work in that area.  If there was no selection made, then the function would assume you wanted to work with the whole document.  Seemed easy enough at first …

… then I got into the various difficulties that automating Word’s Search & Replace via VBA causes.

In the end, and to help my own sanity, a post in the Word VBA group I frequent on LinkedIn came up with a solution to my problem.

It turns out that if you want to remove the duplicate ^p^p from a selection, you need to search for ^p^p and you must remember to switch wildcards off (as you’re only looking once through a selection). However, the opposite is true if you are looking to do a whole search and replace through a whole document, then you need to replace this with ^13^13 instead.

Or, at least, that’s I got it working in the end.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.