Friday, April 9, 2010

VBScript - How Can I Convert a Tilde-Delimited File to Microsoft Excel Format?

VBScript - How Can I Convert a Tilde-Delimited File to Microsoft Excel Format?

Const ForReading = 1
Const ForWriting = 2

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFile = objFSO.OpenTextFile("C:\Scripts\Test.txt", ForReading)
strContents = objFile.ReadAll
objFile.Close

strContents = Replace(strContents, "~", vbTab)

Set objFile = objFSO.OpenTextFile("C:\Scripts\Test.txt", ForWriting)
objFile.Write strContents
objFile.Close

Set objExcel = CreateObject("Excel.Application")
objExcel.Visible = True

Set objWorkbook = objExcel.Workbooks.Open("C:\Scripts\Test.txt")

[Via]