-
If the filename pattern is consistent, maybe:
[VBA]Option Explicit
Sub example()
MsgBox NextNumber(ThisWorkbook.Path)
End Sub
Function NextNumber(Path As String) As Long
Dim File As Object
Dim lTmp As Long
With CreateObject("Scripting.FileSystemObject").GetFolder(ThisWorkbook.Path)
For Each File In .Files
If Mid(File.Name, InStrRev(File.Name, ".")) Like ".xls*" _
And Left(File.Name, InStrRev(File.Name, ".") - 1) Like "ENQ ####" Then
lTmp = CLng(Split(Left(File.Name, InStrRev(File.Name, ".") - 1), Chr(32))(1))
If lTmp > NextNumber Then NextNumber = lTmp
End If
Next
End With
End Function[/VBA]
Hope that helps,
Mark
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules