none
EXPORTAR DE EXCEL A TXT HOJA COMPLETA, PERO SIN SEPARACION (COMAS, TABS, ETC) RRS feed

  • Pregunta

  • Tengo una planilla en donde en la ultima hoja he dejado los datos de la misma manera como tienen que llegar a txt.

    Entre estos foros encontre esta alternativa:

      Public Sub ExportToTextFile(FName As String, Sep As String, SelectionOnly As Boolean)
            Dim WholeLine As String
            Dim FNum As Integer
            Dim RowNdx As Long
            Dim ColNdx As Integer
            Dim StartRow As Long
            Dim EndRow As Long
            Dim StartCol As Integer
            Dim EndCol As Integer
            Dim CellValue As String
            Application.ScreenUpdating = False
            On Error GoTo EndMacro:
            FNum = FreeFile
            If SelectionOnly = True Then
                With Selection
                    StartRow = .Cells(1).Row
                    StartCol = .Cells(1).Column
                    EndRow = .Cells(.Cells.Count).Row
                    EndCol = .Cells(.Cells.Count).Column
                End With
            Else
                With ActiveSheet.UsedRange
                    StartRow = .Cells(1).Row
                    StartCol = .Cells(1).Column
                    EndRow = .Cells(.Cells.Count).Row
                    EndCol = .Cells(.Cells.Count).Column
                End With
            End If
            Open FName For Output Access Write As #FNum
            For RowNdx = StartRow To EndRow
                WholeLine = ""
                For ColNdx = StartCol To EndCol
                    If Cells(RowNdx, ColNdx).Value = "" Then
                        CellValue = Chr(34) & Chr(34)
                    Else
                        CellValue = Application.WorksheetFunction.Text(Cells(RowNdx, ColNdx).Value, Cells(RowNdx, ColNdx).NumberFormat)
                    End If
                    WholeLine = WholeLine & CellValue & Sep
                Next ColNdx
                WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep))
                Print #FNum, WholeLine
            Next RowNdx
        EndMacro:
            On Error GoTo 0
            Application.ScreenUpdating = True
            Close #FNum
        End Sub

        Sub test()
            ExportToTextFile ThisWorkbook.Path & "\test.txt", "", True
        End Sub

     

    El problema es que solo me graba la celda a1 en el txt generado y lo que yo necesito es que se grave la hoja completa, o a lo menos la columna A

    Espero me puedan ayudar

     

     

    miércoles, 30 de noviembre de 2011 17:06