VBA - 如何获取Excel 2010中目录中最后修改的文件或文件夹 [英] VBA - How to get the last modified file or folder in a directory in Excel 2010
问题描述
我想要做的是比从文件列表中选择一个文件更复杂。我将在一个目录中启动,然后我想更改到最近修改的目录。然后我想在一个子目录中重复该过程,然后在其中,我想选择最近修改的excel文件并打开它。
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 objects / methods should I be looking into?
推荐答案
最简单的功能是
FileDateTime(pathname)
其中pathname可以是文件夹的目录。
where pathname can be a directory for folder.
或者,您可以使用FileSystemObject对象,DateLastModified属性:
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
以上所有内容均可在VBA帮助中进行探讨。
All of the above can be explored in VBA help.
这篇关于VBA - 如何获取Excel 2010中目录中最后修改的文件或文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!