I wanted to write a batch file for following scenario:
I have multiple text file like 1.txt,2.txt...n.txt. Now I want to copy the last line from text file and paste it in specified excel sheet colunm like coln B or H.
Can anyone help me?
Thanks
I wanted to write a batch file for following scenario:
I have multiple text file like 1.txt,2.txt...n.txt. Now I want to copy the last line from text file and paste it in specified excel sheet colunm like coln B or H.
Can anyone help me?
Thanks
In VBScript you can do it like this:
Create your excel file
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open("C:\test.xls")
Go through your text files in a loop, open them and read the last line
Set n = 10 'the number of your files
For i = 0 To n
Const ForReading = 1
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(i & ".txt", ForReading)
Do Until objFile.AtEndOfStream
strLine = objFile.ReadLine
Loop
objFile.Close
Write the data stored in strLine
to your excel file
objExcel.Application.Visible = True
objExcel.Workbooks.Add
objExcel.Cells(i, 1).Value = strLine
Next
Save and close your excel file
objExcel.ActiveWorkbook.Save "C:\test.xls"
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
I have not tested this code, it should just show you an idea how it could possibly work.