Dear Friends,
I am trying to import several text files (around 80 in number) at a time from a folder. The data should be loaded to the excel sheet column wise. I was able to get the macro for loading it one by one where every time i have change the name of the file in the path.
The code in provided below:
How to load all the files at a time in a Excel sheet?
Looking forward for your suggestions.
I am trying to import several text files (around 80 in number) at a time from a folder. The data should be loaded to the excel sheet column wise. I was able to get the macro for loading it one by one where every time i have change the name of the file in the path.
The code in provided below:
Code:
Sub DataLoad()
'
' DataLoad Macro
' DataLoad
'
' Keyboard Shortcut: Ctrl+q
'
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Documents and Settings\Administrator\Desktop\target folder" _ '(I'm mentioning the file name here after target folder)
, Destination:=Range("$A$1"))
.Name = "data1"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 437
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Range("B1").Select
ActiveCell.FormulaR1C1 = ""
Range("B1").Select
ActiveSheet.Paste
Columns("B:B").EntireColumn.AutoFit
ActiveWorkbook.Save
ActiveWorkbook.Save
Range("C1").Select
End Sub
How to load all the files at a time in a Excel sheet?
Looking forward for your suggestions.