Gruppe
Ereignis
Problem
Beim Öffnen der Arbeitsmappe soll in Zelle B1 die nächste Bestellnummer eingetragen werden.
ClassModule: DieseArbeitsmappe
Private Sub Workbook_Open()
Dim vNo As Variant
Dim iCounter As Integer
Dim sPath As String
On Error GoTo ERRORHANDLER
sPath = "c:\temp"
With Application.FileSearch
.Filename = "*.xls"
.SearchSubFolders = False
.LookIn = sPath
.Execute msoSortByFileName
If .FoundFiles.Count > 0 Then
vNo = Dir(.FoundFiles(.FoundFiles.Count))
Else
vNo = 0
End If
End With
With Range("B1")
.NumberFormat = "@"
.Value = Format(CInt(Left(vNo, 4)) + 1, "0000")
End With
Exit Sub
ERRORHANDLER:
MsgBox "Sie müssen das Verzeichnis anpassen!"
End Sub