Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, and 2016. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Ignoring Smart Quotes when Comparing Text.

Ignoring Smart Quotes when Comparing Text

Written by Allen Wyatt (last updated December 15, 2020)
This tip applies to Word 2007, 2010, 2013, and 2016


1

Lee has a macro that compares, paragraph by paragraph, two documents. He needs a way to discount the use of smart quotes within a paragraph. In other words, if two paragraphs are similar in every way--except one uses smart quotes and the other doesn't--Lee still wants to consider the paragraphs equivalent.

The easiest way to handle this situation is to simply replace any smart quotes with regular quotes, and then do the comparison. For instance, assuming that your macro steps through the document and assigns the text of a paragraph to a variable (such as sThisPar), then you can get rid of smart quotes in the text by using this code:

sThisPar = RepText(sThisPar, Chr(145), "'")
sThisPar = RepText(sThisPar, Chr(146), "'")
sThisPar = RepText(sThisPar, Chr(147), Chr(34))
sThisPar = RepText(sThisPar, Chr(148), Chr(34))

These lines replace the smart versions of opening and closing quotes and apostrophes with their "plain" equivalents. This code relies upon a function called RepText, which is not shown in this tip. The routine does nothing but replace the occurrence of one piece of text with another. In some versions of VBA you can use the Replace command instead, which is built into those versions of the language.

While you are at it, you may also want to replace other Word-specific characters with their plain equivalents. The following lines replace, respectively, en dashes, em dashes, and ellipses.

sThisPar = RepText(sThisPar, Chr(150), "-")
sThisPar = RepText(sThisPar, Chr(151), "--")
sThisPar = RepText(sThisPar, Chr(133), "...")

Once the replacements are done, you can then compare the text in the paragraphs with much more confidence.

If you cannot modify your macro code for some reason, then you may want to simply replace the smart quotes in your documents with regular quotes prior to running the macro. Open the document, turn off automatic smart quotes (in the AutoCorrect dialog box), and then do two find and replace operations to, first, replace each quote with a quote (put the quote in both the Find What and Replace With boxes) and, second, to replace each apostrophe with an apostrophe. You can then run your macros and the comparison should go smoother.

Note:

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 (11983) applies to Microsoft Word 2007, 2010, 2013, and 2016. You can find a version of this tip for the older menu interface of Word here: Ignoring Smart Quotes when Comparing Text.

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

MORE FROM ALLEN

Automatically Breaking Text

Want to convert the text in a cell so that it wraps after every word? You could edit the cell and press Alt+Enter after ...

Discover More

Understanding DATE Field Formatting

One of the most commonly used fields is the DATE field. You can specify how the DATE field displays the current date by ...

Discover More

Counting Changed Words

Track Changes is a handy tool for those who need to see how a document changes over time. If you have a long document ...

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)

Plain Text Pasting as the Default

Pasting 'plain text' into a document is one of the most common ways of pasting information. Wouldn't it be great if this ...

Discover More

Highlighting Buried Verbs

Checking the grammar in a document can be complex, especially when it comes to advanced evaluations such as buried verbs. ...

Discover More

Breaking Into Sentences

Macros allow you to easily extend what you can do with Word. If you have a common editing task, that task can often be ...

Discover More
Subscribe

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

View most recent newsletter.

Comments

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

2016-11-05 05:02:48

Barry

This is nice, but how does the first sThisPar get initialized in the first place? I mean, without Lee's comparison macro this tip doesn't do us much good. Would Lee be willing to share his macro with the Tips.Net world?


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.

Videos
Subscribe

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.