Word 2003 - 如何使用宏更改样式?

发布于 2024-08-24 20:33:28 字数 304 浏览 6 评论 0原文

是否可以创建 Word 2003 宏来更改文档某些部分的字体样式?

例如,假设我有一个文档,其中大部分文本为粗体斜体和 12 号字体。我想用带下划线的 14 点字体替换具有这些特征的所有文本。

我已经在 Google、StackOverflow 和 Microsoft 网站 上进行了一些搜索但我还没有找到任何讨论这是否可能的内容。

有什么帮助吗?

Is it possible to create a Word 2003 Macro to change the font style of certain segments of a document?

For example, say I have a document that has a large portion of text as bold italic and 12 point font. I'd like to replace all text with these characteristics with underlined 14 point font.

I've already done some searches on Google, StackOverflow and Microsoft's website but I haven't been able to find anything that discusses if this is even possible.

Any help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

可是我不能没有你 2024-08-31 20:33:28

是的,您需要使用 .Find 对象及其子 .Replacement 内容。您可以对选择(有限运行)、范围(段落、故事等)或整个文档执行此操作。下面的示例适用于整个文档 (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

Yeah, you'll want to use the .Find object and it's child .Replacement content. You can do this on a Selection (limited run), a Range (paragraphs, stories, etc.) or the whole document. The sample below is for the whole document (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
暗藏城府 2024-08-31 20:33:28

与往常一样,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 打开“查找和替换”,然后指定适当的查找格式和替换格式)

As always, Word's macro recorder can be of great help:

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

(To generate the macro start the macro recorder, press Ctrl+H to open Find & Replace and then specify the appropriate find format and replacment format)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文