開啟一個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
myDoc.Close True
Next
Application.ScreenUpdating = True
End Sub
開啟一個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