确定一组文件中的最大值

我有一个文件夹,其中包含许多文件,其文件名结构如下:

SOP-JV-**125**-VLG-BK White Vinyl Sizes-EN-10172019

每个文件都有-作为分隔符。

我正在编写一个Sub,它将根据用户使用MS access中的表格填写的某些值为用户创建一个新文件。

我该如何提取文件并确定最高的SOP ID(我在上面的文件名中加粗的值)?

ccyzzxt 回答:确定一组文件中的最大值

我会使用filesystemobject做类似的事情,虽然我还没有测试过这段代码,但是只要有机会,我就会做。

Public Function GetMaxNumber(strPath As String,_
                                Optional strDelim As String = "-",_
                                Optional lngSection As Long = 2) As Long

Dim fso As Scripting.FileSystemObject
Dim fld As Scripting.Folder
Dim fl As Scripting.File
Dim s() As String
Dim l As Long

Set fso = New Scripting.FileSystemObject
Set fld = fso.GetFolder(strPath)

For Each fl In fld.Files
    s = Split(fl.Name,strDelim)
    l = CLng(s(lngSection))
    If l > GetMaxNumber Then GetMaxNumber = l
Next fl

End Function
本文链接:https://www.f2er.com/3165798.html

大家都在问