|
- Private Sub CommandButton1_Click()
- Dim wbook As Workbook
- Dim xx()
- Application.ScreenUpdating = False
- p = 1
- lastrow = [d65535].End(xlUp).Row
- If lastrow > 1 Then Range("a2:g" & lastrow).ClearContents
- lj = ThisWorkbook.Path
- wbn = ThisWorkbook.Name
- dirna = Dir(lj & "\*.xls")
- Do While dirna <> ""
- temp = lj & "" & dirna
- If dirna <> wbn Then
- If WorkbookOpen(CStr(dirna)) Then
- Set wbook = Workbooks(CStr(dirna))
- Else
- Set wbook = Workbooks.Open(temp)
- End If
- For i = 1 To wbook.Sheets.Count
- With wbook.Sheets(i)
- shtn = .Name
- pm = .Cells(4, 1)
- lr = .[a65535].End(xlUp).Row
- arr = .Range("a2:e" & lr)
- If lr = 9 Then
- ReDim Preserve xx(1 To 7, 1 To p)
- '文件名 品名 工作表名称 B列 C列 D列 E列
- xx(1, p) = dirna
- xx(2, p) = pm
- xx(3, p) = shtn
- xx(4, p) = arr(2, 2)
- xx(5, p) = arr(2, 3)
- xx(6, p) = arr(2, 4)
- xx(7, p) = arr(2, 5)
- p = p + 1
- ElseIf lr > 9 Then
- ReDim Preserve xx(1 To 7, 1 To p)
- '文件名 品名 工作表名称 B列 C列 D列 E列
- xx(1, p) = dirna
- xx(2, p) = pm
- xx(3, p) = shtn
- xx(4, p) = arr(2, 2)
- xx(5, p) = arr(2, 3)
- xx(6, p) = arr(2, 4)
- xx(7, p) = arr(2, 5)
- p = p + 1
- For j = 3 To UBound(arr)
- ReDim Preserve xx(1 To 7, 1 To p)
- xx(4, p) = arr(j, 2)
- xx(5, p) = arr(j, 3)
- xx(6, p) = arr(j, 4)
- xx(7, p) = arr(j, 5)
- p = p + 1
- Next
- End If
- End With
- Next
- wbook.Close
- End If
- dirna = Dir
- Loop
-
-
- If p > 1 Then Range("a2:g" & p) = Application.Transpose(xx)
-
- Application.ScreenUpdating = True
- MsgBox " 提取完毕 !~", , "提示"
- End Sub
复制代码 各位老师好,这个是坛子里一位老师的代码,我试了一下,完美运行,现在我有个想法,能否在遍历的过程中判断一下文件日期,如果文件创建日期是今天 则提取这个文件数据,如果文件创建或者修改日期不是今天,则提示 xx文件“为过期文件”忽略不计,请问我这个想法是否能够实现。
|
|