Option
Explicit
Private
Function
GetMaxNummer()
As
String
Dim
oFile
As
Object
Dim
iNr
As
Integer
, iMaxNr
As
Integer
Dim
sPath
As
String
sPath =
"D:\Test"
With
CreateObject(
"Scripting.FileSystemObject"
).GetFolder(sPath)
For
Each
oFile
In
.Files
iNr = Val(Split(Split(oFile.Name,
"."
)(0) &
"-"
,
"-"
)(1))
If
iNr > iMaxNr
Then
iMaxNr = iNr
GetMaxNummer = Mid$(Split(oFile.Name,
"-"
)(0) &
"-"
_
& Right$(
"000"
& iMaxNr + 1, 4), 4)
End
If
Next
oFile
End
With
End
Function
Private
Sub
Workbook_Open()
With
ThisWorkbook.Sheets(
"Tabelle1"
)
.Cells(7, 4).value = GetMaxNummer()
End
With
End
Sub