adit
adit

Reputation: 95

converting ; delimited CSV to tab delimited CSV

I want to convert ;-delimited CSV to tab-delimited CSV. I have tried some options. I can convert it into tab delimited text file but I need tab delimited CSV file as the output. I need a VBScript code.

I have tried the following code which works but convert to tab delimited text file but I want tab delimited CSV file

Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
Dim objFile : Set objFile = objFSO.OpenTextFile("\\vss22\Export\List\Export_File.csv")
Dim objOut : Set objOut = objFSO.CreateTextFile("\\vss22\Export\List\Export_File.txt")

arrData = objFile.ReadAll
objOut.Write Replace(Replace(arrData, ";",vbTab), chr(34), "")
objFile.Close
objOut.Close

Edit: Here is my Input file sample. I used the code as provided by @ansgar, but semicolon (;) is not replaced by tab.

PIM ID;Parent Product;Maintenance;MCH
 1;10001;10001;ABC
 2;20001;20001;ABC
 3;30001;30001;ABC

Output file is

PIM ID;Parent Product;Maintenance;MCH
 11000110001ABC
 22000120001ABC
 33000130001ABC

Here is the code I am using:

file = "\\vwq2702\HeilerExport\TaskList\Archive\List Values.csv"

Set fso = CreateObject("Scripting.FileSystemObject")

txt = fso.OpenTextFile(file).ReadAll
fso.OpenTextFile(file, 2).Write Replace(Replace(txt, ";", vbTab), Chr(34), "")

Upvotes: 0

Views: 2130

Answers (1)

Ansgar Wiechers
Ansgar Wiechers

Reputation: 200213

Just write the modified text back to the original file (after reading the file must be closed before you can open it for writing):

file = "\\vss22\Export\List\Export_File.csv"

Set fso = CreateObject("Scripting.FileSystemObject")

txt = fso.OpenTextFile(file).ReadAll
fso.OpenTextFile(file, 2).Write Replace(Replace(txt, ";", vbTab), Chr(34), "")

Upvotes: 2

Related Questions