bottom
Great WordTips!
         
Your e-mail address is safe!
Close Note

Tips.Net > WordTips Home > Formatting > Character Formatting > Replacing Quoted Text with Italics

Replacing Quoted Text with Italics

Summary: In many documents it is preferable to have special terms formatted as italics when they are first used. Some people, however, often place quote marks around such text. This tip provides a handy macro that can step through a document and make sure that any text surrounded by quote marks is converted to italics text. (This tip works with Microsoft Word 97, Word 2000, Word 2002, and Word 2003.)

In many word processors, an author may call out material with quote marks. For instance, the first time a term is introduced, the author may enclose the term in quote marks. In Word, however, you can call out information with italics. Manually changing quoted material to italics can be very time consuming. The following macro, QuotesToItalics, will check the current paragraph for quoted material. If there is any, it will delete the quotes and change the text between the quotes to italics. If the quote marks are unbalanced (there is an opening or closing quote mark with no corresponding closing or opening quote mark), then the quote mark is ignored and no changes are made. The macro will work with either regular quotes or smart quotes.

Sub QuotesToItalic()
    Dim Redo As Integer, Ptr As Integer, Ptr1 As Integer
    Dim P As String, P1 As String
    If Selection.ExtendMode Then Exit Sub
    Redo = -1
    While Redo
        Selection.StartOf Unit:=wdParagraph, Extend:=wdMove
        Selection.MoveEnd Unit:=wdParagraph
        P = Selection.Text
        Ptr = InStr(P, Chr(34))
        If Ptr = 0 Then Ptr = InStr(P, Chr$(147))
        If Ptr > 0 Then
            Selection.MoveLeft Unit:=wdCharacter, Extend:=wdMove
            Selection.MoveRight Unit:=wdCharacter, Count:=Ptr
            Selection.MoveEnd Unit:=wdParagraph
            P1 = Selection.Text
            Ptr1 = InStr(P1, Chr(34))
            If Ptr1 = 0 Then
                Ptr1 = InStr(P1, Chr$(148))
                EndChar = Chr$(148)
            Else
                EndChar = Chr$(34)
            End If
            If Ptr1 > 0 Then
                Selection.MoveLeft Unit:=wdCharacter, Count:=2, _
                  Extend:=wdMove
                Selection.Delete Unit:=wdCharacter
                Selection.MoveRight Unit:=wdCharacter, _
                  Count:=Ptr1 - 1, Extend:=wdExtend
                Selection.Font.Italic = True
                Selection.MoveRight Unit:=wdCharacter, Extend:=wdMove
                Selection.Delete Unit:=wdCharacter
            Else
                Selection.MoveRight Unit:=wdCharacter, Extend:=wdMove
                Redo = 0
            End If
        Else
            Selection.MoveRight Unit:=wdCharacter, Extend:=wdMove
            Redo = 0
        End If
    Wend
End Sub

Tip #264 applies to Microsoft Word versions: 97 | 2000 | 2002 | 2003


Find and Replace Almost Anything! An invaluable resource for learning how to harness the full power of Word's search and replace capabilities. You'll discover everything you need in order to master all the intricacies of finding and replacing elements of your document, including the super-powerful ?wildcard searches? available in Word.
 
Check out WordTips: Find and Replace today!

Helpful Links

Ask a Word Question
Make a Comment

Tips.Net Home
Tips.Net Store

WordTips FAQ
WordTips Premium

Learn Access Now

Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips

Advertise on the
WordTips Site

 

Great Info!

Get tips like this every week in WordTips, a free productivity newsletter. Enter your e-mail address and click "Subscribe."
     
(Your e-mail address will never be shared with anyone, ever.)