View Single Post
Old 11-14-2007, 11:12 PM   #64
Stephanos
Connoisseur
Stephanos doesn't litterStephanos doesn't litter
 
Posts: 62
Karma: 133
Join Date: Oct 2007
Location: Minnesota, USA
Device: Kobo Aura Edition 2
Someone a while back asked about a Word macro to convert text marked with underscores to italics. This code works for me:

Code:
Sub UnderscoresToItalics()
'
' UnderscoreToItalics Macro
' Macro recorded 11/14/2007 by Stephen Lins
'
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "_<*_"
        .Replacement.Text = "^&"
        .Forward = True
        .Wrap = wdFindContinue
        .Format = True
        .Replacement.Font.Italic = wdToggle
        .MatchCase = False
        .MatchWholeWord = False
        .MatchAllWordForms = False
        .MatchSoundsLike = False
        .MatchWildcards = True
    End With
    Selection.Find.Execute Replace:=wdReplaceAll
    
    Selection.Find.ClearFormatting
    Selection.Find.Replacement.ClearFormatting
    With Selection.Find
        .Text = "_"
        .Replacement.Text = ""
        .Forward = True
        .Wrap = wdFindContinue
        .Format = False
        .MatchCase = False
        .MatchWholeWord = False
        .MatchWildcards = False
        .MatchSoundsLike = False
        .MatchAllWordForms = False
    End With
    Selection.Find.Execute Replace:=wdReplaceAll

End Sub
Stephanos is offline   Reply With Quote