|
窗体代码
Private Sub CheckBox1_Click() '全选
Dim f As Boolean, i&
f = CheckBox1.Value
With ListBox1
For i = 0 To .ListCount - 1
.Selected(i) = f
Next
End With
End Sub
Private Sub CommandButton1_Click()
Dim arr, i&, m&, n&, d As Object, wb As Workbook
Application.ScreenUpdating = False
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
With wb.Sheets(.List(i, 1)).UsedRange
For j = 2 To UBound(arr)
.Replace arr(j, 1), arr(j, 2), n
Next
End With
End If
Next
End With
wb.Close 1
Application.ScreenUpdating = True
End Sub
Private Sub UserForm_Initialize()
With ListBox1
.RowSource = ""
.ColumnCount = 2
If UBound(arr, 2) > 1 Then
.List = WorksheetFunction.Transpose(arr)
Else
.AddItem arr(1, 1)
.List(0, 1) = arr(2, 1)
End If
.MultiSelect = fmMultiSelectMulti
.ListStyle = fmListStyleOption
End With
End Sub
Private Sub CommandButton2_Click() '退出
Unload Me
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer) '退出窗体时清空数组
Erase arr, brr
End Sub
|
|