Macro Won't Limit Replacements to a Selection

by Allen Wyatt
(last updated October 31, 2020)

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


Unable to Use Bulleting and Numbering

Got a document where you just can't get bullets and numbering to work right? It could be that your document is corrupted. ...

Discover More

Adding Hyperlinks

Adding a hyperlink to a text selection is easy to do in Word. All you need to do is make a couple of clicks and specify ...

Discover More

Displaying the First Worksheet in a Macro

When creating macros, you often have to know how to display individual worksheets. VBA provides several ways you can ...

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)

Converting Numbers to Strings

VBA is great at working with both strings and numbers. At some point, you may have a number you need to convert to a ...

Discover More

Writing a Macro from Scratch

Creating macros can help extend what you can do in Word. If you work with macros, you know that creating macros from ...

Discover More

Determining a Paragraph's Style in VBA

When processing a document via a macro, it is often helpful to understand what style has been applied to a paragraph. You ...

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 + 7?

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.