Word 2003 - How to use a macro to change styles?

Can I create a Word 2003 macro to change the font style for certain segments of a document?

For example, let's say I have a document that has most of the text in bold italics and 12-point type. I would like to replace all the text with these characteristics with an underlined font of 14 points.

I have already done some searches on Google, StackOverflow, and the Microsoft website , but I could not find anything that would be discussed, if even possible.

Any help?

+3
source share
2 answers

, .Find .Replacement . Selection ( ), a Range (, ..) . (ActiveDocument.Content).

Sub FindReplaceStyle()
    With ActiveDocument.Content.Find
        .ClearFormatting

        With .Font
            .Bold = True
            .Size = 14
            .Italic = True
        End With

        .Format = True

        With .Replacement
            .ClearFormatting
            With .Font
                .Bold = False
                .Italic = False
                .Underline = wdUnderlineSingle
                .Size = 12
            End With
        End With

        .Execute Forward:=True, Replace:=wdReplaceAll, _
            FindText:="", ReplaceWith:=""
    End With
End Sub
+4

, Word :

Selection.Find.ClearFormatting
With Selection.Find.Font
    .Size = 12
    .Bold = True
    .Italic = True
End With
Selection.Find.Replacement.ClearFormatting
With Selection.Find.Replacement.Font
    .Size = 14
    .Bold = False
    .Italic = False
    .Underline = wdUnderlineSingle
End With
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

( , , Ctrl + H, Find and Replace, )

+2

Source: https://habr.com/ru/post/1736406/


All Articles