如何在 Excel 2010 中使用 VBA 获取目录中最后修改的文件

发布于 2024-11-16 11:43:19 字数 445 浏览 3 评论 0原文

我正在寻找一种使用 VBA 在 Excel 2010 中执行此操作的方法。

过去在 Excel 2003 中可以使用 Application.FileSearch 方法,但该方法已被弃用。 (见下文)

Dim sFileName As String

sFileName = ""
With Application.FileSearch
    .NewSearch
    .LookIn = sDir
    .Filename = "*.*"
    .Execute msoSortByLastModified, msoSortOrderDescending

    If .FoundFiles.Count > 0 Then sFileName = .FoundFiles(1)

End With

您知道如何在 Excel 2010 中执行此操作吗?

谢谢

Im looking for a way to do this in Excel 2010 using VBA.

It used to be possible in Excel 2003 using the Application.FileSearch method, but this has be depreciated. (see below)

Dim sFileName As String

sFileName = ""
With Application.FileSearch
    .NewSearch
    .LookIn = sDir
    .Filename = "*.*"
    .Execute msoSortByLastModified, msoSortOrderDescending

    If .FoundFiles.Count > 0 Then sFileName = .FoundFiles(1)

End With

Any ideas how to do this in Excel 2010?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人的旅程 2024-11-23 11:43:19

如果可以使用 FileSystemObject,则可以使用此处< /a>.

总结一下:

Dim fso As Scripting.FileSystemObject
Dim fol As Scripting.Folder
Dim fdr As Scripting.Folder
Dim fil As Scripting.File
Dim flc As Scripting.Folders

Set fso = CreateObject("Scripting.FileSystemObject")
Set fol = fso.GetFolder("YourPathName")
Set flc = fol.SubFolders

For Each fdr In flc
  For Each fil In fdr.Files
        Debug.Print fil.DateLastModified
  Next fil
Next fdr

Set fso = Nothing
Set fol = Nothing
Set flc = Nothing

If using the FileSystemObject is acceptable, you could use the method described here.

To summarize:

Dim fso As Scripting.FileSystemObject
Dim fol As Scripting.Folder
Dim fdr As Scripting.Folder
Dim fil As Scripting.File
Dim flc As Scripting.Folders

Set fso = CreateObject("Scripting.FileSystemObject")
Set fol = fso.GetFolder("YourPathName")
Set flc = fol.SubFolders

For Each fdr In flc
  For Each fil In fdr.Files
        Debug.Print fil.DateLastModified
  Next fil
Next fdr

Set fso = Nothing
Set fol = Nothing
Set flc = Nothing
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文