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

2025-01-07 04:01:55
推荐回答(1个)
回答1:

你的代码中查找内容为空,替换内容也为空,所以运行后不会有任何效果
给你一个例程(把所有红色字替换为蓝色字):
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