[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 7660
  • Last Modified:

Convert Excel Sheet into a text (tab delimited) file

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.

Thanks.
0
CMILLER
Asked:
CMILLER
  • 2
  • 2
2 Solutions
 
Elton PascuaCommented:
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.
saveasdelimited.xlsm
0
 
Bill PrewCommented:
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)

    objExcel.application.visible=false
    objExcel.application.displayalerts=false

    objExcelBook.SaveAs FileName & "txt", xlText

    objExcel.Application.Quit
    objExcel.Quit   

    Set objExcel = Nothing
    set objExcelBook = Nothing

Next

Open in new window

~bp
1
 
CMILLERAuthor Commented:
Bill,

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?

-Thanks
0
 
Bill PrewCommented:
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?

~bp
0
 
CMILLERAuthor Commented:
It gets uploaded into another system, it should be fine because it matches from previous files.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now