Sub 批量替换多个文档中的指定词语()

Application.Visible = False

Dim fpath As String, fname As String, arr, i As Integer, doc As Document

fpath = "e:\test\"

fname = "test1,test2,test3"

arr = Split(fname, ",")

For i = LBound(arr) To UBound(arr)

Set doc = Documents.Open(fpath & arr(i) & ".docm")

With doc

With Selection.Find

.ClearFormatting

.Text = "万琼"

.Replacement.ClearFormatting

.Replacement.Text = "万群"

.Execute Replace:=wdReplaceAll

End With

.Save

.Close

End With

Next i

Application.Visible = True

End Sub

Sub 批量替换多个文档中的指定词语2()

Application.Visible = False

Dim fpath As String, fname As String, arr, i As Integer, doc As Document, hik As Hyperlink

fpath = " F:\wwuhn\novel\白鹿原\"

fname = Dir(fpath & "*.html")

Do While fname <> ""

Set doc = Documents.Open(fpath & fname)

With doc

With Selection.Find

.ClearFormatting

.Text = "色*"

.Replacement.ClearFormatting

.Replacement.Text = "色"

.Execute Replace:=wdReplaceAll

End With

.Save

.Close

End With

fname = Dir

Loop

MsgBox "all replaced"

Application.Visible = True

End Sub