Category Archives: QTP Scripting

how to append a row into an existing excel sheet?

How to append data to an excel sheet using QTP – VB script

So for this first you have to determine the last row in the excel sheet and then +1 to the last row of the existing excel sheet will be the row number that you will be appending to.

Example code:

Const  exCellTypeLastCell = 20

Set objectExcel = CreateObject(“Excel.Application”)

objectExcel.Visible = True

Set objectWorkbook = objectExcel.Workbooks.add()

Set objectWorksheet = objectWorkbook.Worksheets(1)

 

objectWorksheets.Cells(1,1) = 1

objectWorksheets.Cells(2,1) = 2

objectWorksheets.Cells(3,1) = 3

objectWorksheets.Cells(4,1) = 4

objectWorksheets.Cells(5,1) = 5

 

Set objectRange = objectWorksheet.UsedRange

objectRange.SpecialCells(xlCellTypeLastCell).Active

 

intNewRow = obj.Excel.ActiveCell.Row + 1

strNewCell = “A” & intNewRow

objectExcel.Range(strNewCell).Activate