Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Run time error - Excel object
#1
Hi,
I have a simple code where it creates excel object and add data to it. But i am getting the below run time error when i execute it. Can some please check and let me know solution.

run time error : ActiveX component can't create object: 'Excel.Application'

Thanks in advance.
Reply
#2
Is statement like:
CreateObject("Excel.Application")
Reply
#3
Yes kavitha. With that statement only i am getting the runtime error.



Kavitha, if i run the piece of code individually from QTP, it is working fine.

But, if add the funtion definition to the .vbs file and then call it from QTP, it is not working. .vbs is associated to the script. Can you please reply back immediately if you have solution.

Thanks ..
Reply
#4
Wink 
HI Sasi,

I think you should double check whether the function is properly called from the Script.

You can use the "Alt+G" to check that.

Smile
Reply
#5
Hi saini,
i have checked it. it is fine.
Reply
#6
Hi Sasi
please check my code, i tried to simulate your error.
1. Function definition:
Code:
Public Function ReadExcel() Set appExcel = CreateObject("Excel.Application") Set objWorkBook = appExcel.Workbooks.Open ("C:\Documents and Settings\Administrator\Desktop\ActualizedTrades_06Mar10.xls") 'opens the sheet Set objSheet = appExcel.Sheets("ACTUALIZED_TRADE") ' To select particular sheet Column_Count=objSheet.usedrange.columns.count Row_Count=objSheet.usedrange.rows.count Environment.value("data1")=objSheet.cells(1.1).value End Function

2. Associate .vbs file in settings >> resources

3. Main script in QTP:
Code:
Call ReadExcel() MsgBox Environment.Value("data1") ' This line will print the cell data

This is working fine for me. can you please check, is it the way you are trying to do? OR am i understanding it other way?
Reply
#7
Kavitha,
Thank you so much for the reply. Here probably, the problem is , when i run the script in the invisible mode, then it is throwing this error. But if i run the script from QTP UI, it is not working. I am copying the code here for your reference. Please have a look.



Code:
public Function Export_Result(TestID,Driver_Script,Res,Comments) Dim objExcel,objBook,objSheet,i,columnCount,rowCount ' Initializing the Excel sheet Set objExcel = CreateObject("Excel.Application") Set objBook = objExcel.Workbooks.Open("Q:\Automation\Reports\Results.xls") Set objSheet=objBook.Worksheets("Test_Results") 'Getting the TimeStamp ResultTime=now ' Getting the used rows range rowCount=objSheet.usedrange.rows.count ' Writing in Excel Sheet objExcel.Worksheets("Test_Results").Cells(rowCount+1, 2).Value = TestID objExcel.Worksheets("Test_Results").Cells(rowCount+1, 3).Value = Driver_Script objExcel.Worksheets("Test_Results").Cells(rowCount+1, 4).Value = Res objExcel.Worksheets("Test_Results").Cells(rowCount+1, 4).Font.Bold = true If ucase(Res) = "PASS" Then objExcel.Worksheets("Test_Results").Cells(rowCount+1, 4).Font.ColorIndex = 10 else objExcel.Worksheets("Test_Results").Cells(rowCount+1, 4).Font.ColorIndex = 3 End If objExcel.Worksheets("Test_Results").Cells(rowCount+1, 6).Value = ResultTime 'Writing the Comments objExcel.Worksheets("Test_Results").Cells(rowCount+1, 5).Value = Comments Export_Result = true ' Saving and closing the work book objBook.Save objExcel.Workbooks.Close objExcel.Quit End Function

Thanks
Sasi.C
Reply
#8
Hi sasi
I tried your code it self.It is working fine for bothe the cases mentioned below:
1. When i run the script from QTP UI.
2. when i run the script in the invisible mode (after replacing the parameters with data).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  General run error when Exist fails msacks 1 2,436 02-08-2019, 02:12 AM
Last Post: Ankur
  Trying to create List box in excel sheet at Run time with values yes No JACKSPARROW 0 2,151 01-17-2017, 11:05 AM
Last Post: JACKSPARROW
  General Object Error(Find Object Error) akhandesh 1 4,151 02-24-2016, 01:05 PM
Last Post: sindhus
Rolleyes The test run cannot continue due to an unrecoverable error neerndg123 3 9,577 09-17-2015, 08:27 PM
Last Post: ananthakumarbe
  HI, i'm having a run time error ,please help? Awzar 0 3,046 01-24-2015, 06:52 AM
Last Post: Awzar

Forum Jump:


Users browsing this thread: 1 Guest(s)