Excel函数,search最大通配符(*)

我有以下functionsearch文件path,修改文件date。 但是如果我的文件在最后有一个通配符,那么这个函数返回一个12:00 。 这是因为带有通配符的文件在path中会有很多选项,并且不确定要返回什么值。

我怎样才能告诉这个函数来获取max通配符文件的path名称。

例如: *Stack/Over/Flow_*.csv* (a1)将返回12:00(a2)因为实际的文件夹将包含*Stack/Over/Flow_1.csv*, *Stack/Over/Flow_2.csv*, *Stack/Over/Flow_3.csv.* 。 解决方法是将文件path更改为1,并返回适当的值。 但是我想要这个通配符的max

是否有可能返回哪个修改date的max是每个更大的? 或者,你是否build议只改变通配符(*)为1,并使用函数?

  Public Function getmodifieddateoffile(FilePath As String) On Error GoTo ExitWithError If FilePath = "" Then Exit Function End If If Dir(FilePath) <> "" Then 'This creates an instance of the MS Scripting Runtime FileSystemObject class Set oFS = CreateObject("Scripting.FileSystemObject") getmodifieddateoffile = oFS.GetFile(FilePath).DateLastModified Else End If Exit Function ExitWithError: End Function 

任何帮助将不胜感激。

你可以遍历文件夹中的所有文件,并自己计算最大值?

循环方法:

使用VBA循环浏览文件夹中的文件?

以下代码将返回在path中使用通配符的最长时间

 Public Function GetFileDate(strFile As String) As Date Dim lastDate As Date Dim FileName As String Dim FilePath As String FileName = Split(strFile, "\")(UBound(Split(strFile, "\"))) FilePath = Replace(strFile, FileName, vbNullString) FileName = Dir(FilePath & FileName) Do While FileName <> vbNullString If lastDate < FileDateTime(FilePath & FileName) Then lastDate = FileDateTime(FilePath & FileName) End If FileName = Dir Loop GetFileDate = lastDate End Function