G
Gerritvans
Hi,
I have a number of txt files in a directory and wants to read them b
EXCEL.
The names of the files are defined by a formula.
However sometimes the formula create a filename which not reall
exists. So before I open the file in EXCEL I want to check or that fil
exists. To do that I used the code below:
Sub test()
With Application.FileSearch
.NewSearch
.LookIn = (Interaction.Environ$("userprofile") & "\M
Documents\Test files\")
.SearchSubFolders = False
.Filename = "up12_7.txt"
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub
The problem is that in this case the MsgBox will report that 2 file
exist, "up12_7.txt" and "up12_70.txt", inspite the fact that
.MatchTextExactly = True is used.
How can I change this, so I'm sure it will only look to the fil
"up12_7.txt"?
Thanks for you help by forehand.
Best regards,
Gerri
I have a number of txt files in a directory and wants to read them b
EXCEL.
The names of the files are defined by a formula.
However sometimes the formula create a filename which not reall
exists. So before I open the file in EXCEL I want to check or that fil
exists. To do that I used the code below:
Sub test()
With Application.FileSearch
.NewSearch
.LookIn = (Interaction.Environ$("userprofile") & "\M
Documents\Test files\")
.SearchSubFolders = False
.Filename = "up12_7.txt"
.MatchTextExactly = True
.FileType = msoFileTypeAllFiles
If .Execute() > 0 Then
MsgBox "There were " & .FoundFiles.Count & _
" file(s) found."
For i = 1 To .FoundFiles.Count
MsgBox .FoundFiles(i)
Next i
Else
MsgBox "There were no files found."
End If
End With
End Sub
The problem is that in this case the MsgBox will report that 2 file
exist, "up12_7.txt" and "up12_70.txt", inspite the fact that
.MatchTextExactly = True is used.
How can I change this, so I'm sure it will only look to the fil
"up12_7.txt"?
Thanks for you help by forehand.
Best regards,
Gerri