打开一个word文件,按键盘上alt+F11键。
插入一个模块,粘贴下面的代码。
将代码里面的【原来的字符】和【要替换的字符】修改成自己要替换的内容和被替换的内容会。
按f5选择要批量修改的文件所在的文件夹。完成
Sub 批量替换()
Application.ScreenUpdating = False
Dim MyPath As String
Dim i As Integer
Dim myDoc As Document
With Application.FileDialog(msoFileDialogFolderPicker)
.Title = "选择目标文件夹"
If .Show = -1 Then
MyPath = .SelectedItems(1)
Else
Exit Sub
End If
End With
With Application.FileSearch
.LookIn = MyPath
.FileType = msoFileTypeWordDocuments
If .Execute > 0 Then
For i = 1 To .FoundFiles.Count
Set myDoc = Documents.Open(Filename:=.FoundFiles(i), Visible:=False)
With myDoc.Range.Find
.ClearFormatting
.Replacement.ClearFormatting
.Execute findtext:="原来的字符", replacewith:="要替换的字符", MatchWildcards:=False, replace:=wdReplaceAll
End With
myDoc.Close True
Next
End If
End With
Application.ScreenUpdating = True
End Sub。