N
N
NaksRif2014-04-14 13:31:57
excel
NaksRif, 2014-04-14 13:31:57

VBS - how to create a script to convert CSV to TXT?

Hello, earlier I used a script to convert xls to tab delimited txt:
Set objArgs = WScript.Arguments
InputName = objArgs(0)
OutputName = objArgs(1)
Set objExcel = CreateObject("Excel.application")
objExcel.application.visible =false
objExcel.application.displayalerts=false
set objExcelBook = objExcel.Workbooks.Open(InputName)
objExcelBook.SaveAs OutputName, -4158
objExcel.Application.Quit
objExcel.Quit
But now we need to do the same, but from CSV.
As far as I understand, it should save in the format I need if I use -4158 or 20. But in both cases, if the source file is csv, the script saves txt with delimiters ;

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2014-04-14
@NaksRif

Const OpenAsDefault = -2
Const FailIfNotExist = 0
Const ForReading = 1
Const ForWriting = 2
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set fCSVFile = _
oFSO.OpenTextFile("C:\path\file.csv", ForReading, FailIfNotExist , OpenAsDefault)
sFileContents = fCSVFile.ReadAll
fCSVFile.Close
sFileContents = Replace(sFileContents, ";",vbTab))
Set fCSVFile = oFSO.OpenTextFile("C:\path\file.csv", ForWriting, True)
fCSVFile.Write( sFileContents)
fCSVFile.Close
In general, separators are used from the Region and system language settings. Try replacing ; to a tab and run your script.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question