有如下文档,要求删除氇筐塘瓠里面的重复字符。
二、建立宏。主要代码如下
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
三、运行宏
四、结果如下