UFT Version: 12.02(Build: 2374)
OS: Windows 7(64-Bit)
In my application, there is a DataGrid and an "Export to Excel Button". When I click on that Button, an excel file(Data.xlsx) is opened containing all the data present in the Grid. I just need to save this excel File to a location. I am using the 'GetObject' method to get the reference to the opened Excel File as shown in the below code.
Issue: When I run this code in Debug Mode, it works fine, I do not get any error and the excel gets saved at correct location successfully. But when I run the same code(Normal Run-not in Debug), I get the Error Code: 429(ActiveX Component Can't Create Object') as shown below. I am not sure why I am getting this issue in Normal Run.
Code:
Dim l_objExcel, l_objExcelBook
Execute "Set l_objExcel = GetObject(,""Excel.Application"")" 'getting error 429 here in Normal Run
'I could have just used- Set l_objExcel = GetObject(,"Excel.Application") but it doesn't seem to work. It throws the syntax error(Expected Expression) at this line
Set l_objExcelBook = l_objExcel.ActiveWorkBook
l_objExcelBook.SaveAs strSavePath 'strSavePath contains the File save location
l_objExcelBook.Close
l_ObjExcel.Quit
Set l_objExcelBook = Nothing
Set l_objExcel = Nothing
EDIT1: If I use the following line in the code, I get a syntax error shown in attached image.
Set l_objExcel = GetObject("",""Excel.Application"")
EDIT 2: Just a summary,
If I use the below line, Ii don't get any error during debug but get the error 429 during the normal run.
Execute "Set l_objExcel = GetObject(,""Excel.Application"")"
If I use the below line, I get the syntax error "Expected Expression"
Set l_objExcel = GetObject(,"Excel.Application")
If I use the below line, I do not get any error at this line, but start getting the error 424(Object required) in the line where I am trying to save the File.
Set l_objExcel = GetObject("","Excel.Application")