Micro Focus QTP (UFT) Forums
How to handle opening an excel during run time? - 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 handle opening an excel during run time? (/Thread-How-to-handle-opening-an-excel-during-run-time)



How to handle opening an excel during run time? - Ravi_Chandra - 02-22-2011

Hi,

Below is the scenario:

I have to open an excel file from the application during run time. And I have to get the record count from that excel sheet.
It is taking more seconds to open the excel sheet when data is more.

Used below code but did not work:

Code:
Public Function Export_Debug()
    
Browser("X").Dialog("File Download").WinButton("Open").Click

Do
   Wait(2)
   On Error Resume Next
   Set objExcel = Getobject(,"Excel.Application")
Loop Until objExcel.Visible = True

rowCount = objExcel.ActiveWorkbook.ActiveSheet.usedrange.rows.count
Reporter.ReportEvent micDone, "Record Count in Excel", "Record Count is: " & rowCount

objExcel.Quit
End Function

Can anyone help me with solution?

Thanks,
Ravi.


RE: How to handle opening an excel during run time? - tester_rahul - 02-23-2011

I have an alternative solution.
Try doing this.
use datatable.importsheet "<Path of xlx file> and then
count number of rows of the data table



RE: How to handle opening an excel during run time? - Rekhapramod - 02-23-2011

Hi,

Try to use the below code

Code:
strFileName="C:\Documents and Settings\qtp\Desktop\Login_Details.xls"
strSQLStatement="Select * from [Dummy$]'"

Dim objAdCon, objAdRs
Set objAdCon = CreateObject("ADODB.Connection")
objAdCon.Open "DRIVER={Microsoft Excel Driver (*.xls)};DBQ="&strFileName &";Readonly=True"

Set objAdRs = CreateObject("ADODB.Recordset")
objAdRs.Open strSQLStatement, objAdCon,3
MsgBox objAdRs.RecordCount

Regards,
RP