|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
代码供参考。。。- Sub ykcbf() '//2024.3.4
- Dim fns As New Collection
- Set sh = ThisWorkbook.Sheets("Sheet1")
- With Application.FileDialog(msoFileDialogFolderPicker)
- .Title = "请选择文件夹"
- .InitialFileName = ThisWorkbook.Path & ""
- If .Show = -1 Then
- p = .SelectedItems(1) & ""
- End If
- End With
- Set Fso = CreateObject("Scripting.FileSystemObject")
- Set ff = Fso.GetFolder(p)
- GetFiles ff, fns, Fso
- ReDim brr(1 To fns.Count, 1 To 6)
- bt = Array("文件名称", "文件位置", "创建日期", "修改日期", "文件类型", "文件大小")
- For Each f In fns
- m = m + 1
- For x = 0 To 5
- brr(m, x + 1) = f(x)
- Next
- Next
- With sh
- .Cells.Clear
- .[a1].Resize(1, 6) = bt
- .[a1].Resize(1, 6).Interior.Color = 49407
- With .[a2].Resize(m, 6)
- .Value = brr
- .Borders.LineStyle = 1
- .VerticalAlignment = xlCenter
- .HorizontalAlignment = xlLeft '//靠左
- .Borders.Weight = xlThin
- .EntireColumn.AutoFit
- End With
- For i = 2 To m + 1
- .Hyperlinks.Add Anchor:=.Cells(i, 1), Address:=.Cells(i, 2)
- Next
- End With
- End Sub
- Function GetFiles(ff, fns, Fso)
- For Each f In ff.Files
- If f.Name Like "*.xls*" Then
- If InStr(f, "~$") = 0 Then
- If InStr(f, ThisWorkbook.Name) = 0 Then
- fns.Add Array(f.Name, f.Path, f.DateCreated, f.DateLastModified, f.Type, Format(f.Size / 1048576, "0.00MB"))
- End If
- End If
- End If
- Next
- For Each fd In ff.SubFolders
- Call GetFiles(fd, fns, Fso)
- Next
- End Function
复制代码
|
评分
-
1
查看全部评分
-
|