"Jessie" said:
Hello.
Is there a way to import all .txt files in a specific
folder without typing the names specifically?
Jessie
Jessie
You can use the Dir function to loop through a folder and get all of the file
names. Below is a very basic example of this:
Public Sub sImportTextFiles(strFolder As String)
On Error GoTo E_Handle
Dim strFile As String
If Right(strFolder, 1) <> "\" Then strFolder = strFolder & "\"
strFile = Dir(strFolder, vbNormal)
Do Until strFile = ""
' Import files here by using DoCmd.TransferText or VBA File I/O Operations
strFile = Dir
Loop
sExit:
On Error Resume Next
Exit Sub
E_Handle:
MsgBox Err.Description & vbCrLf & "sImportTextFiles", vbOKOnly +
vbCritical, "Error: " & Err.Number
Resume sExit
End Sub