I want to import multiple TXT files into excel (into the same sheet - every file has only 6 rows). How can I do the files path change in every cycle (I will take it in a for cycle)?
Sub openfile()
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Users\HarrsionDavid\Desktop\\source\customer.txt", _
Destination:=Range("A1"))
.Name = "customer.txt"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 1250
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(1, 9, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Range("A1:C3").Selection
Selection.Delete Shift:=x1Up
Range("A1:C3").Selection
Selection.Delete Shift:=x1Up
End Sub
In this question (Import multiple text files into excel) there is an answer, but I need to change the file name only in the path, because the file names will be get from an other excel column. On Google and Stackoveflow I have no found anything.