|
Sub 提取信息()
Application.ScreenUpdating = False
Dim ar As Variant, br As Variant
Dim i As Long
Dim arr()
Set sht = ThisWorkbook.Worksheets(1)
sht.[a1].CurrentRegion.Offset(1) = Empty
Set fso = CreateObject("Scripting.FileSystemObject")
Set obmapp = CreateObject("Shell.Application").BrowseForFolder(0, "请选择文件目录:", 0, 0) '选择文件夹对话框
If obmapp Is Nothing Then MsgBox "您没有选择文件夹!": End '如果选择了文件夹
fp = obmapp.Self.Path '把选择的文件夹的路劲赋值给变量fp
f = Dir(fp & "\*.csv")
ReDim arr(1 To 10000, 1 To 7)
Do While f <> ""
If f <> ThisWorkbook.Name Then
n = n + 1
arr(n, 1) = fp '文件夹路劲
arr(n, 2) = f '文件名称
Set objfile = fso.GetFile(fp & "\" & f) '
arr(n, 3) = objfile.DateLastModified '修改时间
arr(n, 4) = objfile.DateCreated '文件创建时间
arr(n, 5) = FormatNumber(objfile.Size / 1024, -1) '文件大小
sht.Hyperlinks.Add anchor:=sht.Cells(n + 1, 6), Address:=fp & "\" & f, SubAddress:="", TextToDisplay:=f ''超链接
Set wb = Workbooks.Open(fp & "\" & f, 0)
With wb.Worksheets(1)
r = .Cells(Rows.Count, 1).End(xlUp).Row
ar = .Range("a1:a" & r)
End With
wb.Close False
sht.Cells(n + 1, 7).Resize(1, UBound(ar)) = Application.Transpose(ar)
End If
f = Dir
Loop
If n <> "" Then sht.[a2].Resize(n, 5) = arr
Application.ScreenUpdating = True
MsgBox "ok!"
End Sub
|
|