在現有EXCEL檔案要去開啟資料夾中最近存檔的EXCEL檔案
每次都要用時間排序再開啟.....很累
在此資料夾"E:\Jason\EXCEL\Test"中有多個EXCEL檔案(約80個)
有舊版的(.xls)也有新版的(.xlsx及.xlsm)
請問EXCEL VBA要如何寫
才能開啟此資料夾中最近存檔的EXCEL檔案
試試看FileSystemObject
sub find_new_excel()
dim oFso as object, oFolder as object, file as object
dim myFile as string, myFolder as string, t as date
myFolder = "E:\Jason\EXCEL\Test"
set oFso = createobject("Scripting.FileSystemObject")
Set oFolder = oFso.GetFolder(myFolder)
t=0
for each file in oFolder.Files
if file.name like "*.xls*" then
if file.DateLastModified > t then
t = file.DateLastModified
myfile = file.name
end if
end if
next file
workbooks.open myFolder & "\" & myfile
end sub