Secrets of the Office Masters: Using a Macro to Replace Straight Quotes with Curly Quotes

Large writing projects demand special attention. The first order of business in undertaking a major project is to settle on a template. A template, as you've seen in this chapter, contains styles that define how the document will appear. Add to that AutoText entries, toolbars crafted for the work at hand, and custom macros to take over the most onerous, repetitive (or, if you're lucky, difficult) work, and you'll have a template that's an effective tool for everyone involved in the project.

Macros in big-project templates run the entire gamut of VBA/Word capabilities, but one of the most common requirements you'll see over and over again is the need to scan a document and convert "curly" quotes (Microsoft calls them "smart" quotes) to "straight" quotes. Somehow, page layout software still gets confused by simple curly quotes, and putting a curly quote in the body of an e-mail message is just an invitation to disaster.

This program saves the current document, changes all curly quotes to straight quotes, and then saves the revised document with an XXX Straight Quotes.doc filename (see the following code).

Public Sub Cleanup()
Dim bReplaceQuotes As Boolean
ActiveDocument.Save
bReplaceQuotes = Options.AutoFormatAsYouTypeReplaceQuotes
Options.AutoFormatAsYouTypeReplaceQuotes = False
With ActiveDocument.Range.Find
    .ClearFormatting
    .Text = Chr(145)
    With .Replacement
        .ClearFormatting
        .Text = Chr(39)
    End With
    .Execute Replace:=wdReplaceAll, Format:=False
    .Text = Chr(146)
    With .Replacement
        .ClearFormatting
        .Text = Chr(39)
    End With
    .Execute Replace:=wdReplaceAll, Format:=False
    .Text = Chr(147)
    With .Replacement
        .ClearFormatting
        .Text = Chr(34)
    End With
    .Execute Replace:=wdReplaceAll, Format:=False
    .Text = Chr(148)
    With .Replacement
        .ClearFormatting
        .Text = Chr(34)
    End With
    .Execute Replace:=wdReplaceAll, Format:=False
End With
Options.AutoFormatAsYouTypeReplaceQuotes = bReplaceQuotes
sFileName = ActiveDocument.Name
sFileName = WordBasic.[filenameinfo$](sFileName, 4)
ActiveDocument.SaveAs sFileName & " Straight Quotes.doc"
End Sub

To enter the macro, follow the instructions in Chapter 38, "Using Macros to Automate Office Tasks."

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.227.9