Macro Won't Limit Replacements to a Selection

Written by Allen Wyatt (last updated October 31, 2020)
This tip applies to Word 2010, 2013, 2016, 2019, and Word in Microsoft 365

Roger recently updated from Word 2007 to Word 2019. In Word 2007 he created a macro that would, for text he selected, replace all hard returns with a space. It worked great, making the changes in just the selection. In Word 2019 it does the replacement not just in the selected text, but in the whole document. His macro has the .Wrap property of the Find object set to wdFindAsk, but it seems to be ignored. Roger wonders why the macro doesn't work the same in Word 2019 as it did in Word 2007.

This is, flat out, a bug in Word. It was first noticed in Word 2010, and has yet to be corrected by Microsoft. The problem is the use of wdFindAsk. Until such point as Microsoft decides to fix the problem (so that wdFindAsk works as it should), the only solution is to change the .Wrap property to wdFindStop, which causes the Find and Replace operation to stop at the end of the selected text.

There are also workarounds you can implement. The easiest would be to have your macro ask the user, before doing the Find and Replace operation, if just the selection should be affected or if the entire document should be affected. Based on the response, you could set the .Wrap property to wdFindStop or wdFindContinue, as appropriate. A different workaround that approximates the correct behavior of wdFindAsk can be found at this web page:


If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (13795) applies to Microsoft Word 2010, 2013, 2016, 2019, and Word in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...


Closing Documents after a Hyperlink

When you click a hyperlink that takes you to another document, Word dutifully opens the new document in its own window. ...

Discover More

Word Count for a Section

Dynamic word counts for your entire document are easy to get when you use using fields. There is no built-in method to ...

Discover More

Sorting a Text Selection

Word gives you the option to sort selected groups of text. You can do text, date or number sorts on whole paragraphs or ...

Discover More

Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!

More WordTips (ribbon)

Toggling Font Assignments in a Macro

If you need to quickly switch a text selection from one typeface to another, one way you can do it is with a macro. This ...

Discover More

Checking for a Text Selection Length

Need to know if the user selected some text before running your macro? Here’s how to make that check.

Discover More

Determining the Size of a File

When processing a document using a macro, you may need to know the precise size of a particular file. The way you figure ...

Discover More

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.


If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 7 + 1?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)

This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.


FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.