Excel VBA – 检查是否存在更新的.xlsm

你能帮我解决这个问题吗? 我有分布在公司的.xlsm文件。 每个公司成员都有一个应付方式,并有权访问networking驱动器上的相同文件夹(例如V:/ Excel / Apps)我发现了一个小function来检查文件是否存在:

Function fileExists(s_directory As String, s_fileName As String) As Boolean Dim obj_fso As Object Set obj_fso = CreateObject("Scripting.FileSystemObject") fileExists = obj_fso.fileExists(s_directory & "\" & s_fileName) End Function 

但我真的不知道如何检查相同名称的文件是否更新。 我可以直接在文件名中使用版本,但它不能解决我的问题,因为我的例如excelApp_0.1.xlsm无法知道,如果较新的search版本将是v0.2或0.8或1.6。 你有什么build议吗?

使用obj_fso.getFile(filespec)来获取FILE对象,然后使用file.DateCreated

感谢UncleO,它的工作原理是:-)

 Function newerFileExists(s_directory As String, s_fileName As String) As Boolean Dim obj_fso As Object Set obj_fso = CreateObject("Scripting.FileSystemObject") Dim fileExists As Boolean fileExists = obj_fso.fileExists(s_directory & "\" & s_fileName) If fileExists Then Dim file As Object Dim s As String Dim currentDate As Object Dim newerDate As String Set file = obj_fso.getFile(s_directory & "\" & s_fileName) Set currentDate = ActiveWorkbook.BuiltinDocumentProperties("Creation Date") newerDate = file.DateCreated 's = "Current file creation date: " & currentDate & vbCrLf 's = s & "Newer file creation date: " & newerDate 'MsgBox s If newerDate > currentDate Then newerFileExists = True Else newerFileExists = False End If Else newerFileExists = False End If End Function