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:
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.
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!
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
Creating macros can help extend what you can do in Word. If you work with macros, you know that creating macros from ...Discover More
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."
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.
Visit the WordTips channel on YouTube