RE:macro para convertir archivo de txt a excel
alguna vez hice esto para alguien del foro... espero que te sirva de pista...
Option Explicit
Sub LeerArchivo()
Dim Linea$, n As Long
Dim f$, cod$, num$, tipo$, concepto$, ref$, cargos$, abono$, saldo$
Dim tmp$, fileToOpen
fileToOpen = Application.GetOpenFilename("Archivos de texto (*.txt), *.txt")
If False = fileToOpen Then Exit Sub
n = 0
Application.ScreenUpdating = False
Worksheets(1).Select
[A2].Select
f = ""
Open fileToOpen For Input As #1
Do While Not EOF(1)
Line Input #1, Linea
If InStr(Trim(Linea), " ") > 0 Then
f = Trim(Mid(Linea, 1, InStr(Linea, " ")))
If f <> "" Then
If IsDate(f) Then 'Fecha
With Selection
.Offset(n, 0).Value = cod 'código
.Offset(n, 1).Value = f 'fecha
tmp = Trim(Mid(Linea, Len(f) + 1))
tipo = Trim(Mid(tmp, 1, InStr(tmp, " ")))
.Offset(n, 2).Value = tipo 'tipo
tmp = Trim(Mid(tmp, Len(tipo) + 1))
num = Trim(Mid(tmp, 1, InStr(tmp, " ")))
.Offset(n, 3).Value = num 'nº
saldo = Trim(Mid(tmp, Len(tmp) - 25))
saldo = Replace(saldo, "'", "")
.Offset(n, 8).Value = saldo 'saldo
abono = Trim(Mid(tmp, Len(tmp) - 50, 25))
abono = Replace(abono, "'", "")
.Offset(n, 7).Value = abono 'abono
cargos = Trim(Mid(tmp, Len(tmp) - 75, 25))
cargos = Replace(cargos, "'", "")
.Offset(n, 6).Value = cargos 'cargos
ref = Trim(Mid(tmp, Len(tmp) - 94, 25))
.Offset(n, 5).Value = ref 'referencia
tmp = (Mid(tmp, Len(num) + 1))
concepto = Trim(Mid(tmp, 1, 33))
.Offset(n, 4).Value = concepto 'concepto
End With
n = n + 1
Application.StatusBar = "Procesando " & n & " líneas..."
Else
If InStr(f, "-0") > 0 Then 'Código
cod = f
End If
End If
End If
End If
Loop
Close #1
Application.StatusBar = ""
Application.ScreenUpdating = True
MsgBox n & " líneas procesadas"
End Sub
Saludos, desde Baires, JuanC