Micro Focus QTP (UFT) Forums
How to enter values into excel which is already open using QTP - Printable Version

+- Micro Focus QTP (UFT) Forums (https://www.learnqtp.com/forums)
+-- Forum: Micro Focus UFT (earlier known as QTP) (https://www.learnqtp.com/forums/Forum-Micro-Focus-UFT-earlier-known-as-QTP)
+--- Forum: UFT / QTP Beginners (https://www.learnqtp.com/forums/Forum-UFT-QTP-Beginners)
+--- Thread: How to enter values into excel which is already open using QTP (/Thread-How-to-enter-values-into-excel-which-is-already-open-using-QTP)



How to enter values into excel which is already open using QTP - Narayanan - 12-10-2013

I have a open excel work sheet and i need to activate this sheet and paste values to it. I have written code to open a new excel sheet and paste values into sheet1. But not sure how to activate once again and paste values into sheet2 so on...

Right now, every time i close the excel and open once again


Code:
Set xlsApp = CreateObject("Excel.Application")
xlsApp.Visible = True
Set xlsWorkBook = xlsApp.Workbooks.Open("C:\Users\narayk\Desktop\Test.xlsx")
columncounter  = JavaWindow("").JavaTree("").GetROProperty("columns_count")
For i=1 to columncounter-1
    selectItem =JavaWindow("").JavaTree("").Getcolumnheader(i)
    xlsWorkBook.Worksheets("sheet1").Cells(1,i).value=selectItem
next


'Activate the excel second time and paste values- not working
rowcount  = JavaWindow("").JavaTree("").GetROProperty("")
For R=0 to rowcount-1
    For C=0 to columncounter-1
      counter  = JavaWindow("").JavaTree("").GetColumnValue(R,C)
      xlsWorkBook.Worksheets("sheet2").Cells(2,C).value=selectItem
    Next
Next

I receive Unknow run time error


RE: How to enter values into excel which is already open using QTP - basanth27 - 12-11-2013

Probably it should be,
Code:
For C=1 to columncounter-1