|
新手,想从以下代码开始学习下VBA,麻烦帮忙备注下每一句的意思,越详细越好,谢谢。
Sub test()
Dim arr, brr(1 To 100000, 1 To 3)
Dim wb As Workbook
Dim MyPath As String
Dim MyFile As String
Dim x%, n%, nRow%
Range("a:z").Clear
T = Timer
Application.ScreenUpdating = False
MyPath = ThisWorkbook.Path & "\"
MyFile = Dir(MyPath & "*.xls*")
Do While MyFile <> ""
If MyFile <> ThisWorkbook.Name Then
Set wb = Workbooks.Open(MyPath & MyFile)
With wb.Sheets("单位人员")
nRow = .Cells(Rows.Count, 1).End(xlUp).Row
arr = .Range("a2:b" & nRow)
For i = 1 To UBound(arr)
n = n + 1
brr(n, 1) = VBA.Replace(wb.Name, ".xls", "")
brr(n, 2) = arr(i, 1)
brr(n, 3) = arr(i, 2)
Next i
Erase arr: i = 0
End With
wb.Close False
End If
MyFile = Dir()
Loop
Range("a1:c1") = Array("工作簿名", "姓名", "性质")
Range("a2").Resize(n, 3) = brr
Application.ScreenUpdating = True
MsgBox "一共用时:" & Format(Timer - T, "#0.0000") & " 秒", , "用时" '//提示所用时间
End Sub
|
|