手抄报 安全手抄报 手抄报内容 手抄报图片 英语手抄报 清明节手抄报 节约用水手抄报

使用“宏”删除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中的重复字

© 手抄报圈