Import all files in directory

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!!!
 
D

Douglas J. Steele

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top