我一直在尝试编辑一些代码,这些代码提供了所有子文件夹中所有文件的列表,也给了我在下一列中创建的日期,但我不确定如何。以下是我正在使用的代码:它使文件路径正常但不是文件DateCreateds
Sub startIt()
Dim FileSystem As Object
Dim HostFolder As String
HostFolder = "C:\folderthing"
Set FileSystem = CreateObject("Scripting.FileSystemObject")
DoFolder FileSystem.GetFolder(HostFolder)
End Sub
Sub DoFolder(Folder)
Dim SubFolder
For Each SubFolder In Folder.SubFolders
DoFolder SubFolder
Next
i = Cells(Rows.Count, 1).End(xlUp).Row + 1
Dim File
For Each File In Folder.Files
ActiveSheet.Hyperlinks.Add Anchor:=Cells(i, 1), Address:= _
File.Path, TextToDisplay:=File.Path
ActiveSheet.Add TextToDisplay:=File.DateCreated
i = i + 1
Next
End Sub
答案 0 :(得分:2)
如果您希望列 B 中的日期,则:
Sub startIt()
Dim FileSystem As Object
Dim HostFolder As String
HostFolder = "C:\TestFolder"
Set FileSystem = CreateObject("Scripting.FileSystemObject")
DoFolder FileSystem.GetFolder(HostFolder)
End Sub
Sub DoFolder(Folder)
Dim SubFolder
For Each SubFolder In Folder.SubFolders
DoFolder SubFolder
Next
i = Cells(Rows.Count, 1).End(xlUp).Row + 1
Dim File
For Each File In Folder.Files
ActiveSheet.Hyperlinks.Add Anchor:=Cells(i, 1), Address:= _
File.Path, TextToDisplay:=File.Path
Cells(i, 2).Value = File.DateCreated
i = i + 1
Next
End Sub