none
Export a workbook sheet to space delimited text file (keep tabulation) RRS feed

  • Question

  • I am doing my first VBA code and I need your help please. I have to export a selected sheet as text file and keep the original tabulation. It must have columns seprated by space (" ") in the created text file. Columns to be exported are from A to O. Dealing with the number of lines, It is not constant since it depends on the filtering output. Thanks in advance.
    Tuesday, October 16, 2018 10:41 PM

All replies

  • Hi Moses11,

    The following VBA code also can help you to export the selected range data (for example one column) to the text file, please do as this:

    Sub ExportRangetoFile()
    
    Dim wb As Workbook
    Dim saveFile As String
    Dim WorkRng As Range
    On Error Resume Next
    xTitleId = "KutoolsforExcel"
    Set WorkRng = Application.Selection
    Set WorkRng = Application.InputBox("Range", xTitleId, WorkRng.Address, Type:=8)
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
    Set wb = Application.Workbooks.Add
    WorkRng.Copy
    wb.Worksheets(1).Paste
    saveFile = Application.GetSaveAsFilename(fileFilter:="Text Files (*.txt), *.txt")
    wb.SaveAs Filename:=saveFile, FileFormat:=xlText, CreateBackup:=False
    wb.Close
    Application.CutCopyMode = False
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    End Sub

    For more information, please see the following links:

    Export selection (or one column) to text file with VBA

    Excel VBA Save as tab delimited file

    VBA code to save Excel sheet as tab-delimited text file

    Save/Export Specific Column to Text File

    Hopefully it helps you.

    Best Regards,

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.


    • Edited by Lina-MSFT Wednesday, October 17, 2018 7:16 AM
    Wednesday, October 17, 2018 2:27 AM
  • Hi Moses11,

    Thanks for your asking. Please remember to mark the replies(Include your solution) as answers if they helped and please help us close the thread.

     

    Thank you for understanding. If you have any question, or update, please feel free to let us know.

     

    I wish you a happy life!

     

    Best Regards,

     

    Lina


    MSDN Community Support Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread.

    Monday, October 22, 2018 5:24 AM