How to replace text in quotation marks with italic or highlighted text minus the quotes

Article contributed by Klaus Linke and Dave Rado

This is easy, using a wildcard search and replace.

To do it manually

1.

First make sure Replace straight quotes with Smart quotes is ticked, on the AutoFormat As You Type tab under Tools + Autocorrect; and if you want to use a highlight in the replace, make sure the default highlight colour on the Reviewing toolbar is set to the colour you want.

2.

Then replace " with " (all quotation marks with themselves), which will replace any straight quotes in the document with smart quotes.

3.

Now do your wildcard Find and Replace. 

Your Find What text needs to be:

()(*)()

Note that the quotes must be smart quotes: you can paste them from the document into the Find what: box.

Your Replace with text needs to be:

\2

And in the Replace with: box, either select Format + Font + Italic, or Format + Highlight, depending on your preference.
  

4.

Finally, remove any orpaned opening smart quotes (as you might have if you'd had a quotation spanning more than one paragraph), by replacing the opening quote character (which, as before, you can cut and paste into the dialog from the document; don't type it) with nothing.
  

See also: Finding and replacing characters using wildcards
  

To do it with a macro

Either use:

Sub ReplaceQuotesWithHighlight()

Dim SmartQtSetting As Boolean, DefHighlight As Long

'Make sure smartquotes are turned on
SmartQtSetting = Options.AutoFormatAsYouTypeReplaceQuotes
Options.AutoFormatAsYouTypeReplaceQuotes = True

'Make sure highlight is set to the colour you want, e.g.:
DefHighlight = Options.DefaultHighlightColorIndex
Options.DefaultHighlightColorIndex = wdGreen

With Selection.Find
    'Set parameters
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindContinue
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False

    'First do a replace to make sure quotes are all smartquotes
    .Format = False
    .MatchWildcards = False
    .Text = """"
    .Replacement.Text = """"
    .Execute Replace:=wdReplaceAll

    'Then do the wilcard replace
    .Replacement.Highlight = True
    .Format = True
    .Wrap = wdFindContinue
    .MatchWildcards = True
    'ChrW(8220) is the open quote character and ChrW(8221) is the close quote
    .Text = "(" & ChrW(8220) & ")(*)(" & ChrW(8221) & ")"
    .Replacement.Text = "\2"
    .Execute Replace:=wdReplaceAll

    'Then remove any orphaned opening quotes
    .Format = False
    .Wrap = wdFindContinue
    .MatchWildcards = False
    .Text =ChrW(8220)
    .Replacement.Text = ""
    .Execute Replace:=wdReplaceAll

    'Clear dialog of all non-default settings
    .Text = ""
    .Execute

End With
'Reset options to the way they were
Options.AutoFormatAsYouTypeReplaceQuotes = SmartQtSetting
Options.DefaultHighlightColorIndex = DefHighlight

End Sub


Or use:

Sub ReplaceQuotesWithItalic()

Dim SmartQtSetting As Boolean

'Make sure smartquotes are turned on
SmartQtSetting = Options.AutoFormatAsYouTypeReplaceQuotes
Options.AutoFormatAsYouTypeReplaceQuotes = True

With Selection.Find
    'Set parameters
    .ClearFormatting
    .Replacement.ClearFormatting
    .Forward = True
    .Wrap = wdFindContinue
    .MatchCase = False
    .MatchWholeWord = False
    .MatchAllWordForms = False
    .MatchSoundsLike = False

    'First do a replace to make sure quotes are all smartquotes
    .Format = False
    .MatchWildcards = False
    .Text = """"
    .Replacement.Text = """"
    .Execute Replace:=wdReplaceAll

    'Then do the wilcard replace
    .Replacement.Font.Italic = True
    .Format = True
    .Wrap = wdFindContinue
    .MatchWildcards = True
    'ChrW(8220) is the open quote character and ChrW(8221) is the close quote
    .Text = "(" & ChrW(8220) & ")(*)(" & ChrW(8221) & ")"
    .Replacement.Text = "\2"
    .Execute Replace:=wdReplaceAll

    'Then remove any orphaned opening quotes
    .Format = False
    .Wrap = wdFindContinue
    .MatchWildcards = False
    .Text = ChrW(8220)
    .Replacement.Text = ""
    .Execute Replace:=wdReplaceAll

    'Clear dialog of all non-default settings
    .Text = ""
    .Execute

End With
'Reset options to the way they were
Options.AutoFormatAsYouTypeReplaceQuotes = SmartQtSetting

End Sub


Click to view Terms of Use page

Click to view Disclaimer page