Writing data from text file to excel using VBScript

June 6, 2012 at 15:10:11
Specs: Windows XP
I am reading a file and need to out put all lines of the file to a separate row within in excel. Can some one help. currently I'm only getting the last row.

Dim objFSO, strTextFile, strData, strLine, arrLines

CONST ForReading = 1

'name of the text file
strTextFile = "C:\Documents and Settings\SClark\Desktop\4010ControlOutput.txt"

'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Open the text file - strData now contains the whole file
strData = objFSO.OpenTextFile(strTextFile,ForReading).ReadAll

'Split the text file into lines
arrLines = Split(strData,vbCrLf)

Set objExcel = CreateObject("Excel.Application")

objExcel.Visible = True


intRow = 2

objExcel.Cells(1, 1).Value = "4010 Control"

'Step through the lines
For Each strLine in arrLines
strLineArray = Split(strLine,".TXT")
strLine = Trim(strLineArray(0)) &".TXT"
' wscript.echo strLine
objExcel.Cells(intRow, 1).Value = strLine

intRow = intRow + 1

Set objFSO = Nothing

See More: Writing data from text file to excel using VBScript

Report •

June 11, 2012 at 16:19:40
Have you tried just opening the file in Excel?

How To Ask Questions The Smart Way

Report •
Related Solutions

Ask Question