VBA - How to get the last modified file or folder in a directory in Excel 2010

别等时光非礼了梦想. 提交于 2019-12-20 12:31:15

问题


What I want to do is more complex than selecting a file from a list of files. I will start in a directory, then I want to change to the most recently modified directory. I then want to repeat that process in a sub-directory, and then, inside of that, I want to select the most recently modified excel file and open it.

What is the best approach to do this?

What objects / methods should I be looking into?


回答1:


The simplest function is

FileDateTime(pathname)

where pathname can be a directory for folder.

Alternatively, you can use the FileSystemObject object, DateLastModified property:

Dim fileModDate As String

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFile(<filenamestringhere>)

fileModDate = f.DateLastModified

All of the above can be explored in VBA help.



来源:https://stackoverflow.com/questions/6656023/vba-how-to-get-the-last-modified-file-or-folder-in-a-directory-in-excel-2010

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!