Importing multiple files

R

Rick S.

I borrowed a majority of this code from this NG and modified (read destroyed)
it for my needs, now I can't figure what I did wrong.
The macro should import a text file starting in A1, get the last row +1
(counting in column B) and repeat untill all files in the folder are
processed. The only cloumns that should have data are A thru H, row count
will vary.

Initially it appears to work, then the macro starts moving data to other
columns, like taking A1 thru A867 (A thru H) and moving it to I thru P and so
on and adding blank rows from the top down?

Code:
Sub aaa()
'Set Folder path
Folder = "C:\MEASURE-6000\OUTPUT\Test\"

'Create worksheet "Input"
With ThisWorkbook
Set InputSht = Worksheets.Add( _
after:=.Sheets(.Sheets.Count))
InputSht.Name = "Input"
End With
'File name Extension to find
FName = Dir(Folder & "*.OUT")

Do While FName <> ""
'Input data file
With InputSht
'Count rows in column B
InputShtLastRow = .Cells(Rows.Count, "B").End(xlUp).Row
'MsgBox InputShtLastRow    'for testing

'Add data to worksheet and append each new import
With .QueryTables.Add( _
Connection:="TEXT;" & Folder & FName, _
Destination:=.Range("A" & InputShtLastRow + 1))

.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = xlWindows
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = True
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = True
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1)
.Refresh BackgroundQuery:=False
End With
End With
Loop
End Sub

Please help, I only have six or seven brain cells left!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top