Link to home
Start Free TrialLog in
Avatar of danfiggolf
danfiggolf

asked on

Writing to Rows in EXCEL via VBScript

How do I setup the script to write new line to next row in single Worksheet, without opening a new workbook in this script?
Option Explicit

Dim strFile, strInputLog, strOutputLog, objFSO, objInput, objOutput
Dim strLine, blnError, intCount, dtmToday, intSummary
Dim objExcel, objWorkbook

Const ForReading = 1

dtmToday = Now()

' Specify input log file.
strInputLog = "D:\Documents and Settings\figueroadaniel\My Documents\ClassPatchInstallation_0792.log"
' Output file.
strOutputLog = "d:\output.txt"

Set objFSO = CreateObject("Scripting.FileSystemObject")

' Open files.
Set objInput = objFSO.OpenTextfile(strInputLog, ForReading)
Set objOutput = objFSO.CreateTextFile(strOutputLog, True)

' Read each line of input log file.
intCount = 0
blnError = False
Do Until objInput.AtEndOfStream
    strLine = objInput.ReadLine
    intCount = intCount + 1
    If (InStr(strLine, "Class") > 0) Then
    
    	Set objExcel = CreateObject("Excel.Application")
		Set objWorkbook = objExcel.Workbooks.Open("d:\test.xls")

		objExcel.Application.Visible = True
		objWorkbook.WorkSheets(1).Activate
		objWorkbook.WorkSheets(1).Cells(1, 1).Value = strLine
		objExcel.ActiveWorkbook.Close
		objExcel.Application.Quit
   
      
        objOutput.WriteLine intCount
        objOutput.WriteLine strLine
        blnError = True
    Else
        If (blnError = True) Then
            objOutput.WriteLine strLine
            blnError = False
        End If
    End If
Loop

' Close input file.

objInput.Close
objOutput.Close

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of RobSampson
RobSampson
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial