Hello djvice,
Sorry about that, I made a typo in the Like operator for the file name comparison. It is missing an asterisk at the end.
Valid = FileName Like "####-##### (*"
Here is the revised code...
Sub ListFileNames()
Dim FileName As String
Dim FilePath As String
Dim Valid As Boolean
Dim Wks As Worksheet
R = 1 'Starting Row
Set Wks = Worksheets("Sheet1")
FilePath = "C:\Documents and Settings\Admin.ADMINS\My Documents\*.xls"
InputAcct:
Acct = InputBox("Please Enter an Account number.")
If Acct = "" Then Exit Sub
Valid = Acct Like "#####"
If Not Valid Then
MsgBox "Please Enter a 5 digit Account number."
GoTo InputAcct
End If
FileName = Dir(FilePath)
Do While FileName <> ""
Valid = FileName Like "####-##### (*"
If Valid Then
If Mid(FileName, 6, 5) = Acct Then
Wks.Cells(R, "A") = FileName
R = R + 1
End If
End If
FileName = Dir
Loop
End Sub
Sincerely,
Leith Ross
Bookmarks