网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容

使用“宏”删除WORD中的重复字

时间:2024-10-14 05:04:10

有如下文档,要求删除里面的重复字符。

使用“宏”删除WORD中的重复字

二、建立宏。主要代码如下

Dim str As String

Dim bstr As String

Dim cf As String

Dim i As Long

Selection.WholeStory

str = Selection.Text

For i = 1 To Len(str)

Selection.Find.ClearFormatting

Selection.Find.Replacement.ClearFormatting

With Selection.Find

.Text = Mid(str, i, 1)

.Replacement.Text = ""

.Forward = True

.Wrap = wdFindContinue

.Format = False

.MatchCase = True

.MatchWholeWord = False

.MatchByte = True

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

End With

Selection.Find.Execute

If Selection.Find.Found = True Then

Selection.Find.Execute Replace:=wdReplaceAll

Selection.Text = Mid(str, i, 1)

cf = cf & Mid(str, i, 1)

End If

Next i

MsgBox cf

使用“宏”删除WORD中的重复字

三、运行宏

使用“宏”删除WORD中的重复字

四、结果如下

使用“宏”删除WORD中的重复字

© 2025 小知经验
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com