Code:Sub saveProgressiveNumber() Dim fs, snum As String Set fs = CreateObject("Scripting.FileSystemObject") Fname = "Ivan Ivanov-" ' the name must end with - fpath = "your path\" If Dir(fpath & "*.xls*") = "" Then ThisWorkbook.SaveAs (fpath & Fname & "0001.xlsm") Else Set f = fs.GetFolder(fpath) Set NFile = f.Files For Each pf1 In f.Files date3 = pf1.DateLastModified Fname1 = pf1.Name If MDataUM < date3 Then FpathName = pf1 MDataUM = date3 fnameExt = Fname1 End If Next fnum = Val(Mid(FpathName, InStr(FpathName, "-") + 1, 4)) + 1 snum = Format(fnum, "0000") ThisWorkbook.SaveAs (fpath & Fname & snum & ".xlsm") End If End Sub
Bookmarks