Import all files in directory

  • Thread starter Thread starter JenL
  • Start date Start date
J

JenL

I have a seemingly simple stupid question and cannot figure out what I am
doing wrong.
My database is working perfectly. I just have one small problem.

I want to import all .txt files in a given directory. I know some VBA code,
but for ease of use by others in the future in my company I try to do it in a
macro without using code.

So in the FileName field of my TransferText command, I have:
T:\folder\folder1\*.txt

This is not working. How do I tell it to just import ALL .txt files in that
directory?

Thanks!!!
 
You have to do it one file at a time.

Fortunately, though, you can automate it.

Dim strFolder As String
Dim strFile As String

strFolder = "T:\folder\folder1\"
strFile = Dir(strFolder & "*.txt")
Do While Len(strFile) > 0

' Put your TransferText statement here to transfer the concatenation
' of strFolder & strFile

strFile = Dir()
End While
 
Back
Top