求写一段用word VBA程序(宏命令)

发布网友 发布时间:2022-04-26 14:52

我来回答

1个回答

热心网友 时间:2023-10-10 14:50

你的代码中查找内容为空,替换内容也为空,所以运行后不会有任何效果
给你一个例程(把所有红色字替换为蓝色字):
Sub ColorReplace()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Font.Color = wdColorRed
Selection.Find.Replacement.Font.Color = wdColorBlue
With Selection.Find
.Text = ""
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindContinue
.Format = True
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchWildcards = False
.MatchSoundsLike = False
.MatchAllWordForms = False
End With
Selection.Find.Execute Replace:=wdReplaceAll
End Sub追问能不能再改一下,我要的是把替换的字删除掉,还有能不能把要删除字的颜色RGB(221,221,221)写进去。

追答把前面这部分代码
Sub ColorReplace()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Font.Color = wdColorRed
Selection.Find.Replacement.Font.Color = wdColorBlue
改成:
Sub ColorReplace()
Selection.Find.ClearFormatting
Selection.Find.Replacement.ClearFormatting
Selection.Find.Font.Color = RGB(221,221,221)

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com