首页 > 解决方案 > 根据多种字体条件替换 Word VBA 中的文本

问题描述

我正在尝试删除所有带有字体的单词。name.FarEast="Georgia" 和 font.name="Verdana", Bold=true 在文档中,但我找不到 vba 的任何查找功能...(我可以手动设置查找格式)任何人都可以帮忙我和那个?

我已经用尽了我的搜索方法,找不到答案

 With Selection.Find.Bold = True
        .ClearFormatting
        Selection.Font.NameFarEast = "Georgia"
       .Font.Name = "Verdana"
       .Execute FindText:="", ReplaceWith:="", Format:=True, _
        Forward:=True
        End With

'似乎根本不起作用

它只是显示

“未找到方法或数据”

标签: vbafontsms-word

解决方案


您可以遍历所有单词并检查条件。

Sub test1()

Dim sen As Object
Dim wd As Object

For Each sen In ActiveDocument.StoryRanges(1).Sentences

    For Each wd In sen.Words

        With wd
        If .Bold = True  And .Font.Name = "Verdana" And .Font.NameFarEast = "Georgia" Then

            wd.Select
            Selection.Text = ""

        End If
        End With

    Next

Next

End Sub

演示: 只检查粗体字

在此处输入图像描述


推荐阅读