大致做了一个,大家可以给我检查检查,代码:
RojeC29H.rar
(44.29 KB, 下载次数: 78)
Private Sub CommandButton2_Click()
Dim s1 As Date, s2 As Date
Dim s As String, i%
Dim wb As Workbook, rng As Range, SHT As Worksheet
Dim aa As Double
aa = Timer
Application.ScreenUpdating = False
s1 = Me.DTPicker1: s2 = Me.DTPicker2
If s2 < s1 Then MsgBox "Date Select Wrong!": Exit Sub
Set SHT = ThisWorkbook.Sheets("database")
SHT.Cells.ClearContents
With Application.FileSearch
.NewSearch
.LookIn = ThisWorkbook.Path
.Filename = "*.xls"
.Execute msoSortByFileName
For i = 1 To .FoundFiles.Count
If .FoundFiles(i) <> ThisWorkbook.FullName Then
s = Dir(.FoundFiles(i))
s = Split(s, "_")(0)
s = VBA.Format$(s, "0000-00-00")
If CDate(s) >= s1 And CDate(s) <= s2 Then
Set wb = Workbooks.Open(.FoundFiles(i))
Set rng = SHT.[b65536].End(xlUp).Offset(1, 0)
wb.Sheets(1).[a1].CurrentRegion.Copy rng
rng.Offset(0, -1) = s
wb.Close False
End If
End If
Next
End With
SHT.Select: Unload Me
Application.ScreenUpdating = True
MsgBox "Done! Total:=" & VBA.Format$(Timer - aa, "0.00") & "s"
End Sub
|