通过Excelmacros导入文件名不是通过文件名导入文件名

我有一个Excelmacros,从我select的文件夹中导入所有文件,并将其放入工作表中,并且我想按date导入它们(因为文件是图片)而不是文件名,以便将图片放入按照这样的顺序

002_1.jpg (time is 7:00am) 001_1.jpg (time is 7:01am) 003_1.jpg (time is 7:03am) 

不pipe文件名是什么,看看这些文件是如何按照被采取的顺序放置的。 你有什么想法如何修改我目前的macros来做到这一点?

 Sub filegrabber() Dim par, sfil As String Dim r As Range par = Application.InputBox("Enter The Directory Dont forget to add the \") sfil = Dir(par & "*.*", vbDirectory) Set r = ActiveCell Do Until sfil = "" If sfil = "." Or sfil = ".." Then GoTo skipit r = sfil ActiveCell.Hyperlinks.Add r, par & sfil Set r = r.Offset(1) skipit: sfil = Dir$ Loop End Sub 

在将文件添加到工作表之前,使用FileSystemObject检查文件的date。

 Dim FileDirectory, FileName As String Dim r As Range Dim FindThisDate As Date Sub filegrabber() FileDirectory = Application.InputBox("Enter The Directory Dont forget to add the \") enterdate: FindThisDate = Application.InputBox("Enter The Date of files you want to load") If Not IsDate(FindThisDate) Then MsgBox "Please Enter A Valid Date", vbCritical, "Invalid Date" GoTo enterdate Else FindThisDate = CDate(FindThisDate) End If FileName = Dir(FileDirectory & "*.*", vbNormal) 'changed this from vbdirectory cuz you want files, not folders Set r = ActiveCell While FileName <> "" If filedate(FileDirectory & FileName) = FindThisDate Then r = FileName ActiveCell.Hyperlinks.Add r, FileDirectory & FileName Set r = r.Offset(1) End If FileName = Dir$ Wend End Sub Function filedate(FileName) As Date Dim fso, f Set fso = CreateObject("Scripting.FileSystemObject") Set f = fso.GetFile(FileName) filedate = DateValue(f.DateCreated) Set fso = Nothing Set f = Nothing End Function 
    Interesting Posts