VBS Script to Browse For A Text File And Convert It From Comma To Tab Delimited

 

This VBS script will allow you browse for a text file and then convert it from a comma delimited text file to a tab delimited text file. You can also change the Replace string character from the comma to another value such as = as needed.

 

You can also take the script one step further by changing the comma to a string value and the vbTab to yet another sting value by using the syntax here: 

 

strNewFile = Replace(strTextCharacter, "Old_String", "New_String",)

 

VBS Script:

 

Set objDialog = CreateObject("UserAccounts.CommonDialog")

objDialog.Filter = "Text Files|*.Txt"

objDialog.InitialDir = "C:\"

intResult = objDialog.ShowOpen

Set WshShell = WScript.CreateObject("WScript.Shell")

 

Const ForReading = 1

Const ForWriting = 2

 

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile(objDialog.FileName, ForReading)

 

strTextCharacter = objFile.ReadAll

objFile.Close

strNewFile = Replace(strTextCharacter, ",", vbTab)

 

Set objFile = objFSO.OpenTextFile(objDialog.FileName, ForWriting)

objFile.WriteLine strNewFile

objFile.Close

 

MsgBox "Done"

 

 

 

Published Sunday, March 30, 2008 7:43 AM by dhite
Filed under:

Comments

No Comments