Convert Excel Sheet into a text (tab delimited) file

Posted on 2012-08-28
Last Modified: 2012-08-30
I have a excel 2007 file with 62 col  (A-BJ ) with headers and rows 1-200. I need a script to convert the file into a text (tab delimited) file.

I download the original file everyday and I just want a script to convert it without having to open the file and save as.

Question by:CMILLER
    LVL 8

    Assisted Solution

    by:Elton Pascua
    Hope this helps. It asks for the workbook location then saves a text version of the file in the same directory. This overwrites without warning.
    LVL 51

    Accepted Solution

    Here's a VBS approach.  Save as a VBS file, and then you can either drag one or more excel filestoit, and it will save them as tab delim TXT files with the same base name.  Or run from the command line like this:

    cscript cvt.vbs "c:\temp\myfile.xls"

    Const xlText = -4158
    Set objArgs = WScript.Arguments
    For I = 0 to objArgs.Count - 1
        FullName = objArgs(I)
        FileName = Left(objArgs(I), InstrRev(objArgs(I), ".") )
        Set objExcel = CreateObject("Excel.application")
        set objExcelBook = objExcel.Workbooks.Open(FullName)
        objExcelBook.SaveAs FileName & "txt", xlText
        Set objExcel = Nothing
        set objExcelBook = Nothing

    Open in new window


    Author Comment


    Nice, looks great.

    One last question, not all columns are equal in the xls file so when it converts not all the text lines up, there is some over lap. Is there a way to fix that?

    LVL 51

    Expert Comment

    by:Bill Prew
    Do you mean not all columns are of equal length?  If so, then using a tab delimited format, when the resulting file is displayed you may not be aligned.  This is because most viewing utilities or editors will treat a tab character in a "advance to the next multiple of 8" type approach (or something similar).  So if a field can sometimes bo wider than 8, and other shorter than 8, it wont line up when you view it.  No way to change that in a tab delimited format.

    What is the usage for the tab delimited file, does it feed in to another program, or is it just for some type of viewing?


    Author Comment

    It gets uploaded into another system, it should be fine because it matches from previous files.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
    How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
    The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
    This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now