Sub SearchNewFMS()
Dim i As Integer, DateInBase As String, FMSDate As String
path_to_fms = UserForm2.TextBox1.Text
DateInBase = UserForm2.TextBox2.Text
'On Error GoTo ends:
With Application.FileSearch
.LookIn = path_to_fms
.FileName = "*" & "FMS" & "*.txt"
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
For i = 1 To .FoundFiles.Count
FMSDate = CDbl(Mid(.FoundFiles(i), Len(path_to_fms) + 5, 8))
If (FMSDate >= DateInBase) And _
(FMSDate < Format(Date, "YYYYMMDD")) Then UserForm2.TextBox3.Text = FMSDate
Next i
Else
MsgBox "Please, select a correct directory with FMS files!"
End If
End With
End Sub
Dim i As Integer, DateInBase As String, FMSDate As String
path_to_fms = UserForm2.TextBox1.Text
DateInBase = UserForm2.TextBox2.Text
'On Error GoTo ends:
With Application.FileSearch
.LookIn = path_to_fms
.FileName = "*" & "FMS" & "*.txt"
If .Execute(SortBy:=msoSortByFileName, _
SortOrder:=msoSortOrderAscending) > 0 Then
For i = 1 To .FoundFiles.Count
FMSDate = CDbl(Mid(.FoundFiles(i), Len(path_to_fms) + 5, 8))
If (FMSDate >= DateInBase) And _
(FMSDate < Format(Date, "YYYYMMDD")) Then UserForm2.TextBox3.Text = FMSDate
Next i
Else
MsgBox "Please, select a correct directory with FMS files!"
End If
End With
End Sub
add