Macro for Word problems: Find/Replace style


  • Im trying to develop a simple Macro that will find text in my document that is Italic and replace it with a character style... However it seems that when I record the process it omits the point where I select the formating of the font (italic). I don't understand VB and entering what logically should work into the code didn't work.

    The code I get from recording is:

    Sub FindReplace()
    ' FindReplace Macro
    ' Macro recorded 12/9/07 by mac2
        Selection.Find.Replacement.Style = ActiveDocument.Styles( _
            "Font Italic")
        With Selection.Find
            .Text = ""
            .Replacement.Text = ""
            .Forward = True
            .Wrap = wdFindContinue
            .Format = True
            .MatchCase = False
            .MatchWholeWord = False
            .MatchWildcards = False
            .MatchSoundsLike = False
            .MatchAllWordForms = False
        End With
        Selection.Find.Execute Replace:=wdReplaceAll
    End Sub

    Can anybody assist me with the line(s) that I need to get this script to work?
    Wednesday, September 12, 2007 3:24 AM

All replies

  • Hi!

    If you don't find something better you may do like it

    Code Snippet

    For Each i In ActiveDocument.Words
        If i.Font.Name = "Times New Roman" Then i.Font.Name = "Courier New"



    Wednesday, September 12, 2007 12:29 PM
  • Sorry but thats not what im after. Am trying to replace instances of "Italics" with a "Character Style"
    Wednesday, September 12, 2007 10:25 PM
  • I have given you only general example. You may make

    Code Snippet

    For Each i In ActiveDocument.Words
        If i.Font.Italic = True Then i.Font.Name = "Courier New"


    or what you want

    Thursday, September 13, 2007 5:53 AM