Si los archivos se van a guardar en la misma carpeta donde tienes el archivo con la macro entonces utiliza la siguiente macro:
Sub Generar()
'Por.Dante Amor
Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set h1 = Sheets("BASE")
Set h2 = Sheets("ARCHIVO")
Set h3 = Sheets("VARIABLES")
Set h4 = Sheets("SALIDA")
h2.UsedRange.Offset(1, 0).Clear
j = 2
For i = 2 To h1.Range("A" & Rows.Count).End(xlUp).Row
If h1.Cells(i, "A") <> "" And IsNumeric(h1.Cells(i, "A")) Then
h1.Rows(i).Copy h2.Rows(j)
Set b = h3.Columns("A").Find(h1.Cells(i, "B"), lookat:=xlWhole)
If Not b Is Nothing Then
h2.Cells(j, "E") = h3.Cells(b.Row, "C")
h2.Cells(j, "F") = h3.Cells(b.Row, "D")
h2.Cells(j, "G") = h3.Cells(b.Row, "E")
End If
j = j + 1
End If
Next
Call Salida1(h2, h3, h4)
Call Salida2(h2, h3, h4)
MsgBox "Fin"
End Sub
'
Sub Salida2(h2, h3, h4) '
'Por.Dante Amor
h4.Cells.Clear
j = 1
n = 200
For i = 2 To h2.Range("A" & Rows.Count).End(xlUp).Row
If h2.Cells(i, "A") = n Then
h4.Cells(j, "A") = "3" 'indicativo
'h4.Cells(j, "B") = " " '1 blanco
H4.Cells(j, "C") = Format(h2. Cells(i, "E"), "'000") 'banco
H4.Cells(j, "D") = Format(h2. Cells(i, "G"), "'000000000000000000") 'no. Cuenta
H4.Cells(j, "E") = Format(h2. Cells(i, "D"), "'0000000000000") 'importe
H4.Cells(j, "F") = Format(h2. Cells(i, "B"), "'000000000") 'Id
'h4.Cells(j, "G") = " " '2 blancos
h4.Cells(j, "H") = h2.Cells(i, "C") 'nombre
j = j + 1
End If
Next
cols = Array("", "1", "1", "3", "18", "13", "9", "2", "45")
For i = 1 To UBound(cols)
h4.Columns(i).ColumnWidth = cols(i)
Next
'
Call guardar(h3, h4, n)
End Sub
'
Sub Salida1(h2, h3, h4)
'Por.Dante Amor
h4.Cells.Clear
j = 1
n = 100
For i = 2 To h2.Range("A" & Rows.Count).End(xlUp).Row
If h2.Cells(i, "A") = n Then
h4.Cells(j, "A") = Format(h2.Cells(i, "B"), "'000000000") 'ID
'h4.Cells(j, "B") = String(15, " ") 'espacios
h4.Cells(j, "C") = h2.Cells(i, "C") 'nombre
h4.Cells(j, "D") = 1 'indicativo
h4.Cells(j, "E") = Format(h2.Cells(i, "E"), "'000") 'banco
If h2.Cells(i, "E") = 510 Then ag = "'0510" Else ag = "'" 'agregar a no. cuenta
h4.Cells(j, "F") = ag & h2.Cells(i, "G") 'no. cuenta
h4.Cells(j, "G") = h2.Cells(i, "F") 'tipo cuenta
h4.Cells(j, "H") = Format(h2.Cells(i, "D"), "'000000000") 'importe
j = j + 1
End If
Next
cols = Array("", "9", "15", "45", "1", "3", "20", "1", "9")
For i = 1 To UBound(cols)
h4.Columns(i).ColumnWidth = cols(i)
Next
'
Call guardar(h3, h4, n)
End Sub
'
Sub guardar(h3, h4, n)
h4.Copy
Set b = h3.Columns("H").Find(n, lookat:=xlWhole)
If Not b Is Nothing Then
arch = h3.Cells(b.Row, "J")
carp = "\" '& h3.Cells(b.Row, "N") & "\"
Else
arch = "sin nombre"
carp = "\"
End If
ruta = ThisWorkbook.Path & carp
arch = arch & " " & Format(Date, "yyyymm") & ".txt"
ActiveWorkbook.SaveAs Filename:=ruta & arch, FileFormat:=xlTextPrinter, CreateBackup:=False
ActiveWorkbook.Close
End Sub
' : )
'S aludos. Dante Amor. Recuerda valorar la respuesta. G racias
' : )