简体   繁体   中英

Script working in Debug Mode but not in Normal Run - Error Code: 429(ActiveX Component Can't Create Object')

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,

  1. 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"")" 
  2. If I use the below line, I get the syntax error "Expected Expression"

     Set l_objExcel = GetObject(,"Excel.Application") 
  3. 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") 

Just use

Set l_objExcel = GetObject( ,"Excel.Application")

it will show syntax error, but ignore it , your script will run fine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM