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


Counting Values in Table Cells

In Excel it is easy to count how many times a certain character occurs in a column of cells. In Word, it is a bit ...

Discover More

Adding Vertical Lines at the Sides of a Word

Vertical lines are even easier to add around a word than are horizontal lines. There are a variety of methods you can use ...

Discover More

Adjusting Cell Margins for More White Space

Is the information in your cells too jammed up? Here are some ways you can add some white space around that information ...

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)

Controlling the Italic Text Attribute

If you are formatting your document by using a macro, you may need to make some of your text italics. You do that by ...

Discover More

Assigning a Macro to a Shortcut Key

Do you have a macro that you use frequently? Using the File menu to access the macro can be time consuming. This tip ...

Discover More

Determining if Overtype Mode is Active

Your macro may need to determine if the user has overtype mode turned on. You can find out the overtype status easily by ...

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}] 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 six minus 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.

Newest Tips

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.