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:
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (5411) applies to Microsoft Word 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Word (Word 2007 and later) here: Ignoring Smart Quotes when Comparing Text.
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!
Do you want to easily jump to the top of a page in your document? You can use the Go To command to make the shift, or you ...
Discover MoreMacros can be used to read and write all sorts of files. If those files are on a different drive than the current one, ...
Discover MoreIf you develop a macro to process your document, you may want the macro to save the document to disk. This is easily done ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)
Got a version of Word that uses the menu interface (Word 97, Word 2000, Word 2002, or Word 2003)? This site is for you! If you use a later version of Word, visit our WordTips site focusing on the ribbon interface.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments