exportar desde excel a txt desde macro solo algunas columnas
Publicado por Pablo (2 intervenciones) el 18/11/2021 19:08:28
Estimados como estan, tengo una macro con la cual exporta a txt desde excel, pero necesito solo exportar algunas columnas A B C y todas las filas , mi codigo me trae todas las columnas. Que debo cambiar para exportar solo las antes mencionadas [A B C]?.
Este es mi codigo
Sub CreaTXT()
Dim NombreArchivo, RutaArchivo As String
Dim Obj As FileSystemObject
Dim tx As Scripting.TextStream
Dim Ht As Worksheet
Dim i, j, nFilas, nColumnas As Integer
NombreArchivo = "Batch"
RutaArchivo = ActiveWorkbook.Path & "\" & NombreArchivo & ".txt"
Set Obj = New FileSystemObject
Set tx = Obj.CreateTextFile(RutaArchivo)
Set Ht = Worksheets("TXT")
nFilas = Ht.Range("A2", Ht.Range("A2").End(xlDown)).Cells.Count
nColumnas = Ht.Range("A1", Ht.Range("A1").End(xlToRight)).Cells.Count
For i = 1 To nFilas
For j = 1 To nColumnas
tx.Write Ht.Cells(i + 1, j)
Next j
tx.WriteLine
Next i
End Sub
Este es mi codigo
Sub CreaTXT()
Dim NombreArchivo, RutaArchivo As String
Dim Obj As FileSystemObject
Dim tx As Scripting.TextStream
Dim Ht As Worksheet
Dim i, j, nFilas, nColumnas As Integer
NombreArchivo = "Batch"
RutaArchivo = ActiveWorkbook.Path & "\" & NombreArchivo & ".txt"
Set Obj = New FileSystemObject
Set tx = Obj.CreateTextFile(RutaArchivo)
Set Ht = Worksheets("TXT")
nFilas = Ht.Range("A2", Ht.Range("A2").End(xlDown)).Cells.Count
nColumnas = Ht.Range("A1", Ht.Range("A1").End(xlToRight)).Cells.Count
For i = 1 To nFilas
For j = 1 To nColumnas
tx.Write Ht.Cells(i + 1, j)
Next j
tx.WriteLine
Next i
End Sub
Valora esta pregunta


0