|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
楼主,这回再试试!(注意——代码中假设把《歌诀》这个文档放在了 d:\我的文档 文件夹中了,如果不同,你自己修改一下吧!另外,这个文档要永久放在一处,不要改变才能反复用此代码!)
Sub aaa查找入声字()
ActiveDocument.SaveAs FileName:=ActiveDocument.Path & "\" & Left(ActiveDocument.Name, Len(ActiveDocument.Name) - 4) & "_入声" & ".doc" '创建副本
Dim i As String, j As Long, a As String, b As String, c As String, e As Long
a = ActiveDocument.FullName
b = "d:\我的文档\常用入声字歌诀.doc" '歌诀完整文件名(如果路径不同,请自行修改!只此一处!)
Documents.Open FileName:=b
e = InStrRev(b, "\")
c = Mid(b, e + 1)
c = Left(c, Len(c) - 4)
Windows(a).Activate
Selection.EndKey unit:=wdStory
Selection.TypeText Text:="`"
Selection.HomeKey unit:=wdStory
Do
Selection.MoveRight unit:=wdCharacter, Count:=1, Extend:=wdExtend
i = Selection.Text
If i Like "[。,;:!]" Then GoTo skip
Windows(c).Activate
Selection.HomeKey unit:=wdStory
Selection.ClearFormatting
Selection.Find.Execute findtext:=i
If Selection.Find.Found = True Then j = 1 Else j = 0
Windows(a).Activate
If j = 1 Then Selection.Font.Color = wdColorRed: Selection.Font.Bold = True
skip:
Selection.MoveRight unit:=wdCharacter, Count:=1
Loop Until Selection.Text = "`"
Windows(c).Close savechanges:=wdDoNotSaveChanges
ActiveDocument.Characters.Last.Previous.Delete
ActiveDocument.Close savechanges:=wdSaveChanges
Documents.Open FileName:=a
MsgBox "处理完毕!当前文档已经保存!", vbOKOnly + vbExclamation, "查找入声字"
End Sub |
|