Hi everyone,
I am trying to write a small VBA proccedure to import dozens of text files into a worksheet.
The problem is I can't ask the QueryTables.Add function to read a variable for the file name, like the following code, variable Filename is not recognized inside quatation marks or without quatation marks:
Sub ImportData()
Dim FileName as string
Filename = E:\test.txt
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;Filename" _
, Destination:=Range("$A$1"))
.TextFileTabDelimiter = True
.Refresh BackgroundQuery:=False
End With
End Sub
Thanks, please help!