15 years ago
Read and Write into Excel
Hi ALL I am running into some problems trying to read and write to an excel file. I have data I am reading for a data driven test and I would like to write in the last column the result of the ...
Sub Main
FileName = "c:\Test\Data.xls"
Set MsExcel = Sys.OleObject("Excel.Application")
MsExcel.Workbooks.Open FileName
MsExcel.Visible = True
Call RunTestAndInsertResults(MsExcel)
End Sub
Sub RunTestAndInsertResults (Excel)
Dim NumberOfUsedCells
NumberOfUsedCells = GetDimensions(Excel)
For RowsIndex = 1 to NumberOfUsedCells(0)
For ColumnsIndex = 1 to NumberOfUsedCells(1)
Log.Message(Excel.Cells(RowsIndex,ColumnsIndex))
Next
If RowsIndex mod 2 = 0 Then
Excel.Cells(RowsIndex,NumberOfUsedCells(1) + 1).Value = "PASSED"
Else
Excel.Cells(RowsIndex,NumberOfUsedCells(1) + 1).Value = "FAILED"
End If
Next
End Sub
Function GetDimensions(Excel)
Dim Count(1)
xlCellTypeLastCell = 11
Count(0) = Excel.ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Row
Count(1) = Excel.ActiveSheet.Cells.SpecialCells(xlCellTypeLastCell).Column
GetDimensions = Count
End Function