Te anexo la macro Impotar_Txt. También se utiliza la macro Insertar_Archivo, deben ir juntas.
Sub Impotar_Txt()
'
' Por.Dante Amor
'
'
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set h1 = Sheets("Temp")
ruta = ThisWorkbook.Path & "\"
arch = Dir(ruta & "*.txt")
Do While arch <> ""
Call Insertar_Archivo(h1, ruta, arch)
hoja = Left(arch, 2)
existe = False
For Each h In Sheets
If Left(UCase(h.Name), 2) = UCase(hoja) Then
Set h2 = h
existe = True
Exit For
End If
Next
If existe = False Then
Sheets.Add after:=Sheets(Sheets.Count)
Set h2 = ActiveSheet
h2.Name = hoja
End If
h2.Rows("2:" & Rows.Count).Clear
u2 = 2
'u2 = h2.Range("A" & Rows.Count).End(xlUp).Row + 1
u1 = h1.Range("A" & Rows.Count).End(xlUp).Row
h1.Rows("1:" & u1).Copy h2.Range("A" & u2)
arch = Dir()
Loop
'
Application.ScreenUpdating = True
MsgBox "Archivos importados"
End Sub
'
Sub Insertar_Archivo(h1, ruta, arch)
' Por.Dante Amor
'
h1.Cells.Clear
With h1.QueryTables.Add(Connection:="TEXT;" & ruta & arch & "", Destination:=h1.Range("$A$1"))
.Name = "AF002419"
.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 = xlTextQualifierNone
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = True
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
End Sub
sal u dos