office交流網--QQ交流群號

Access培訓群:792054000         Excel免費交流群群:686050929          Outlook交流群:221378704    

Word交流群:218156588             PPT交流群:324131555

用VBA代碼循環錶格當前目録下的所有Excel文件中修改日期爲最新的文件名

2020-05-01 08:00:00
zstmtony
原創
2530

用VBA代碼循環錶格當前目録下的所有Excel文件中修改日期爲最新的文件名


Dim strPath As String
Dim strFile As String
Dim datLast As Date
Dim strLastFile As String
Set fso = CreateObject("Scripting.FileSystemObject")

Path = CurrentProject.Path & ""

strFile = Dir(Path & "*.xls")
strLastFile = ""
datLast = #1/1/1900#

Do While strFile <> ""
   Set f = fso.Getfile(Path & strFile)
   If f.DateLastModified > datLast Then datLast = f.DateLastModified: strLastFile = strFile
   strFile = Dir
Loop

Msgbox "最新的文件" & strFile

分享