You are on page 1of 1

Sub GeneraTxt()

Dim MiRango As Range, Largo As Integer, FilaActual As Long


On Error Resume Next
Set MiRango = Application.InputBox("Seleccione rango a exportar", Type:=8)
On Error GoTo 0
If MiRango Is Nothing Then Exit Sub
Open "C:\Temp\TEXTO.txt" For Output As #1
For Each Celda In MiRango
If Largo <= Len(Celda) Then Largo = 1 + Len(Celda)
Next Celda
FilaActual = MiRango.Cells(1).Row
For Each Celda In MiRango
If FilaActual < Celda.Row Then
FilaActual = Celda.Row: Print #1, ""
End If
Print #1, CStr(Celda); Space(Largo - Len(Celda));
Next Celda
Close #1
Set MiRango = Nothing
End Sub

You might also like