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


Replacing Text Selections

When editing a document, Word normally replaces whatever text you select with whatever you start to type. Here's how to ...

Discover More

A Picture Is Worth a Thousand Words

Nothing beats a screen shot when you are trying to convey information about using the computer. With just a couple of ...

Discover More

Adding Information after the Endnotes

Endnotes appear at the end of the document, right? Not always, as Word provides a way that you can actually add as much ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 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

Determining How Many Styles are Available

Got a macro that processes or uses styles? You definitely need to know how many styles Word has available in the ...

Discover More

Changing the Default Drive

Macros can be used to read and write all sorts of files. If those files are on a different drive than the current one, ...

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 1 + 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.