Home All Groups Group Topic Archive Search About

copy from file paste to an existing xls..



Author
13 Oct 2007 11:14 PM
PK
Dear all
I need to copy data from a text file and then insert it in to an already
existing .xls document.

Ive got this code, but it creates a new xls file instead of adding to an
existing xls file.
(NB the existing .xls file already has data in it.)

any pointers appreaciated.

cheers

Const ForReading = 1
Set oExcel = CreateObject("Excel.Application")
oExcel.Visible = True
oExcel.Workbooks.Add
i = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\passwords.txt", ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
arrLine = Split(strLine, ",")
oExcel.Cells(i, 1).Value = arrLine(0)
i = i + 1
Loop
oExcel.ActiveWorkbook.SaveAs ("c:\newtest.xls")
objFile.Close
oExcel.Quit

AddThis Social Bookmark Button