automate importing multiple files

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to import several hundred text files and several hundred excel files
into an Access database. How can I write a VBA program to import one file
after another, perhaps as part of Do Loop or If..Then..Else procedure?
Thanks.
 
Yes, you can.

Something like the following will find all the .txt files in a given folder
and let you process them one at a time:

Dim strFile As String
Dim strFolder As String

strFolder = "C:\MyFolder\MySubfolder\" ' the final slash is important!
strFile = Dir$(strFolder & "*.txt")
Do While Len(strFile) > 0

' put your code here to use the TransferText method
' The full path to the file will be strFolder & strFile

strFile = Dir$()
Loop
 
Back
Top