|
Private Sub CommandButton1_Click()
Dim arr, i&, m&, n&, d As Object, wb As Workbook, rng As Range, sh As Worksheet
Me.Hide
arr = [a1].CurrentRegion
If [c1] = "匹配替换" Then n = 1 Else n = 2
Set d = CreateObject("scripting.dictionary")
With ListBox1
For i = 0 To .ListCount - 1
If .Selected(i) Then
If Not d.Exists(brr(i + 1)) Then
m = m + 1
If m > 1 Then wb.Close 1
d(brr(i + 1)) = ""
Set wb = Workbooks.Open(brr(i + 1))
End If
Set sh = wb.Sheets(.List(i, 1))
sh.Select
On Error Resume Next
Set rng = Application.InputBox("请选择该工作表替换区域", Type:=8)
If rng Is Nothing Then Set rng = sh.UsedRange '如果不选择区域,则全部替换
On Error GoTo 0
With rng
For j = 2 To UBound(arr)
.Replace arr(j, 1), arr(j, 2), n
Next
End With
Set rng = Nothing '新加
End If
Next
End With
wb.Close 1
Me.Show
End Sub |
|