Command Line Export

F

fjurek

I need to export a sheet to a file in a tab-separated format, to use in a bat
script.
How do I do that ? Is it possible ? Are there any tools ?

Regards

Jurek
 
J

Joel

You can save a workbook with only one worksheet as a csv file by using the
File -Save As menu option and selectt .csv format. These are text files
which can be read by other programs.
 
D

David Biddulph

The OP said he wanted TAB-separated, not COMMA-separated.

Joel is right in his answer as far as File/ Save As, but at that stage one
of the .txt options is TAB-separated.
 
J

Joel

You can always replace tabs with spaces using notepad once the file is saved.
Hopefully there is not commas in the cell data.
 
F

fjurek

Thank you all.
This is all true, and I use it on single files, but I need to use it on many
files and for other manipulations on these data, so I want to have it in a
bat file, and the export should work from the command line or script.

Yours

Jurek
 
J

Joel

Thsi macro will automatically write TAB text

Sub WriteTab()

Const ForReading = 1, ForWriting = 2, ForAppending = 3
Const MyPath = "C:\temp\"
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0

MyTAB = Chr(9)


Set fswrite = CreateObject("Scripting.FileSystemObject")


WriteFileName = "tabtext.txt"


WritePathName = MyPath + WriteFileName
fswrite.CreateTextFile WritePathName
Set fwrite = fswrite.GetFile(WritePathName)
Set tswrite = fwrite.OpenAsTextStream(ForWriting, TristateUseDefault)


LastRow = Rows.Count
Do While (Cells(LastRow, Columns.Count).End(xlToLeft).Column = 1) And _
IsEmpty(Cells(LastRow, 1))

LastRow = LastRow - 1
Loop

For RowCount = 1 To LastRow

LastColumn = Cells(RowCount, Columns.Count).End(xlToLeft).Column
For ColCount = 1 To LastColumn

If ColCount = 1 Then
OutputLine = Cells(RowCount, ColCount)
Else
OutputLine = OutputLine + MyTAB + CStr(Cells(RowCount, ColCount))
End If


Next ColCount

tswrite.WriteLine OutputLine
Next RowCount

tswrite.Close

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top