Hello all
Many thanks for this great forum, and the assistance given to me in the past. I have another question that I am not sure on the answer to.
I have a workbook that will import in as text four certain files from a directory that itself will contain many other files in addition to these four. Lets name these particular files as A.txt, B.txt, C.txt, D.txt.
Each of these imports will be done in turn in the same sub and will be imported each to their own worksheet in the destination workbook.
I would like before I try the import of these files to check firstly if these four source files do indeed exist in their directory. I understand that I can check for the existence of a single file by using say the example code below:
Sub TestFl()
'VBA Check if File Exists
Dim strFileA As String
strFileA = "C:\Users\Data\RawData\A.txt"
If Len(Dir(strFileA))=0 Then
MsgBox "File Does Not Exist"
Else
MsgBox "File Exists"
End If
End Sub
My question would be how could I check for the existence of the four files I want to import. Would the following example work, or would it be too inefficient?
Dim strFileA As String
Dim strFileB As String
Dim strFileC As String
Dim strFileD As String
strFileA = "C:\Users\Data\RawData\A.txt"
strFileB = "C:\Users\Data\RawData\B.txt"
strFileC = "C:\Users\Data\RawData\C.txt"
strFileD = "C:\Users\Data\RawData\D.txt"
If (Len(Dir(strFileA))=0 Or Len(Dir(strFileB))=0 Or Len(Dir(strFileC))=0 Or Len(Dir(strFileD))=0) Then
MsgBox "One of the source files is missing"
Many thanks for taking the time to look at this and for any guidance or advice you can give,
Paul
Many thanks for this great forum, and the assistance given to me in the past. I have another question that I am not sure on the answer to.
I have a workbook that will import in as text four certain files from a directory that itself will contain many other files in addition to these four. Lets name these particular files as A.txt, B.txt, C.txt, D.txt.
Each of these imports will be done in turn in the same sub and will be imported each to their own worksheet in the destination workbook.
I would like before I try the import of these files to check firstly if these four source files do indeed exist in their directory. I understand that I can check for the existence of a single file by using say the example code below:
Sub TestFl()
'VBA Check if File Exists
Dim strFileA As String
strFileA = "C:\Users\Data\RawData\A.txt"
If Len(Dir(strFileA))=0 Then
MsgBox "File Does Not Exist"
Else
MsgBox "File Exists"
End If
End Sub
My question would be how could I check for the existence of the four files I want to import. Would the following example work, or would it be too inefficient?
Dim strFileA As String
Dim strFileB As String
Dim strFileC As String
Dim strFileD As String
strFileA = "C:\Users\Data\RawData\A.txt"
strFileB = "C:\Users\Data\RawData\B.txt"
strFileC = "C:\Users\Data\RawData\C.txt"
strFileD = "C:\Users\Data\RawData\D.txt"
If (Len(Dir(strFileA))=0 Or Len(Dir(strFileB))=0 Or Len(Dir(strFileC))=0 Or Len(Dir(strFileD))=0) Then
MsgBox "One of the source files is missing"
Many thanks for taking the time to look at this and for any guidance or advice you can give,
Paul