|
Option Explicit
Sub TEST()
Dim ar, i&, k&, wdApp As Word.Application, Items As FileDialogSelectedItems, strPath$
strPath = ThisWorkbook.Path & "\"
With Application.FileDialog(1)
With .Filters
.Clear
.Add "Word文档(doc*)", "*.doc*"
End With
.AllowMultiSelect = True
.InitialFileName = strPath
If .Show Then Set Items = .SelectedItems Else Exit Sub
End With
Application.ScreenUpdating = False
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err <> 0 Then
Set wdApp = New Word.Application
End If
For k = 1 To Items.Count
With wdApp.Documents.Open(Items(k))
For i = 2 To UBound(ar)
With .Content.Find
.ClearFormatting
.Text = ar(i, 1)
.Replacement.ClearFormatting
.Replacement.Text = ar(i, 2)
.Execute Replace:=wdReplaceAll
End With
Next i
.Close True
End With
Next k
If Err <> 0 Then wdApp.Quit
Set wdApp = Nothing
Set Items = Nothing
Application.ScreenUpdating = True
Beep
End Sub
|
评分
-
1
查看全部评分
-
|