Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7403721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T05:09:05+00:00 2026-05-29T05:09:05+00:00

I have an Excel 2010 workbook. I need to save the used range of

  • 0

I have an Excel 2010 workbook. I need to save the used range of each of its worksheets as a tab-delimited text file with no quotes, with the same filename as the workbook and with an extension given by the worksheet name.

Note that Excel stupidly surrounds a value by quotes whenever it sees a comma, even though the delimiter is a tab; other than that, the normal “Save As” / “Text (Tab delimited)” would be fine.

I would prefer to do that using VBA code from within Excel.

If there is a Python solution, I’d be interested too. But at this point pywin32 support for Python 3 is only experimental, so I am not sure I can use it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T05:09:06+00:00Added an answer on May 29, 2026 at 5:09 am

    Ok here is a slightly complex routine which I wrote couple of months back for one of my clients. This code exports the Excel Worksheet to a Fixed Width File without QUOTES. Screenshots also attached. I am sure this code can be made even better 🙂

    TRIED AND TESTED

    Option Explicit
    
    '~~> Change this to relevant output filename and path
    Const strOutputFile As String = "C:\Output.Csv"
    
    Sub Sample()
        Dim ws As Worksheet
        Dim rng As Range
        Dim MyArray() As Long, MaxLength As Long
        Dim ff As Long, i As Long, lastRow As Long, LastCol As Long
        Dim strOutput As String
    
        On Error GoTo Whoa
    
        Application.ScreenUpdating = False
    
        '~~> Change this to the respective sheet
        Set ws = Sheets("Sheet1")
        LastCol = ws.Cells(1, Columns.Count).End(xlToLeft).Column
    
        '~~> Loop through each Column to get the max size of the field
        For i = 1 To LastCol
            MaxLength = getMaxLength(ws, i)
            ReDim Preserve MyArray(i)
            MyArray(i) = MaxLength
        Next i
    
        ff = FreeFile
    
        '~~> output file
        Open strOutputFile For Output As #ff
    
        '~~> Write to text file
        With ws
            lastRow = .Range("A" & Rows.Count).End(xlUp).Row
    
            For Each rng In .Range("A1:A" & lastRow)
                With rng
                    For i = 1 To UBound(MyArray)
                        '~~> Insert a DELIMITER here if your text has spaces
                        strOutput = strOutput & " " & Left(.Offset(0, i-1).Text & _
                                    String(MyArray(i), " "), MyArray(i))
                    Next i
    
                    Print #ff, Mid(Trim(strOutput), 1)
                    strOutput = Empty
                End With
            Next rng
        End With
    
    LetsContinue:
        On Error Resume Next
            Close #ff
        On Error GoTo 0
        Application.ScreenUpdating = True
        Exit Sub
    Whoa:
        MsgBox Err.Description
        Resume LetsContinue
    End Sub
    
    '~~> Function to get the max size
    Public Function getMaxLength(ws As Worksheet, Col As Long) As Long
        Dim lastRow As Long, j As Long
    
        getMaxLength = 0
    
        lastRow = ws.Range("A" & ws.Rows.Count).End(-4162).Row
    
        For j = 1 To lastRow
            If Len(Trim(ws.Cells(j, Col).Value)) > getMaxLength Then _
            getMaxLength = Len(Trim(ws.Cells(j, Col).Value))
        Next j
    End Function
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an Excel 2010 workbook for financial records. On one worksheet, I have
I have an Excel file that I need to import into a (new) Oracle
I have an Excel 2010 macro application that is made up of several workbook
I need to create a Excel 2010 macro, which changes the SQL Command text
I have a rather complex Excel 2010 file that I automate using python and
I'm using Excel 2010. I'm trying so save my excel file, with this code.
I have made a new Excel 2010 Add-in project, with VS10. When I run
In a cell in Excel sheet I have a Date value like: 01/01/2010 14:30:00
I have an Excel spreadsheet provided as a report, when really its more of
I have an Excel 2007 ODBC connection defined and I need to allow users

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.