Quantcast
Channel: Excel Help Forum - Excel Programming / VBA / Macros
Viewing all articles
Browse latest Browse all 50090

Inported Multiple Delimited Text Files Do Not Format Correctly

$
0
0
Hello everyone,

When more than one txt file is imported, they display horizontally (side by side), instead I would like file 1 to be displayed with file 2 on the next available row, 3 on the next available row and so on. Basically want each new file to be displayed vertically (below the previous file).

This is the code I am working with:
Sub Import_All_Text_Files_2007()

Dim nxt_row As Long

'Change Path
Const strPath As String = "C:\MICHAEL\SCHOOLS\TEST\"
Dim strExtension As String

'Stop Screen Flickering
Application.ScreenUpdating = False

ChDir strPath

'Change extension
strExtension = Dir(strPath & "*.txt")

Do While strExtension <> ""

'Sets Row Number for Data to Begin
nxt_row = Range("A1").End(xlUp).Offset(1, 0).Row

'Below is from a recorded macro importing a text file
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & strPath & strExtension, Destination:=Range("$A$" & nxt_row))
.Name = strExtension
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
'Delimiter Settings:
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = "|"

.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With

strExtension = Dir
Loop

Application.ScreenUpdating = True

End Sub


Thank for all of your help.

Viewing all articles
Browse latest Browse all 50090

Trending Articles