呵呵,等我把<守柔WORD编程代码集>有机会上传的话,你可以尽情地看一下. 请参: 一) 查找与替换的基本代码用法之一 '* +++++++++++++++++++++++++++++++++++++++ '^The Code CopyIn [ThisDocument-ThisDocument]^' '* -------------------------------------------------------------------------- Sub Example()
With ActiveDocument.Content.Find
.ClearFormatting '清除格式设置
.Font.Name = "华文细黑" '查找的字体格式
With .Replacement '替换条件
.ClearFormatting '清除格式设置
.Font.Name = "黑体" '替换成黑体
End With
.Execute FindText:="", ReplaceWith:="", Format:=True, _
Replace:=wdReplaceAll '是格式替换,全部替换
End With
End Sub
'----------------------
二) 查找与替换的基本代码用法之二 '* +++++++++++++++++++++++++++++++++++++++ '^The Code CopyIn [ThisDocument-ThisDocument]^' '* -------------------------------------------------------------------------- Sub Example()
Dim FindChar As String, Fcount As Integer, RepChar As String
On Error Resume Next
Application.ScreenUpdating = False '关闭屏幕更新
FindChar = "《"
RepChar = "["
With ActiveDocument.Content.Find '此处针对全文档
Do While .Execute(findtext:=FindChar) = True '如果发现
Fcount = Fcount + 1 '计数器
Loop
If MsgBox("文档中共发现了" & Fcount & "个" & FindChar & vbCrLf _
& ",按Yes键将进行下一步的替换工作,按No取消", vbYesNo + vbInformation) = vbYes Then
.Execute findtext:=FindChar, Wrap:=wdFindContinue, replacewith:=RepChar, Replace:=wdReplaceAll
End If
End With
Application.ScreenUpdating = True '恢复屏幕更新
End Sub
'----------------------
最好结合你的实例(上传一个附件),否则易走弯路,OK? |