Forum Discussion

VenkataRanga's avatar
VenkataRanga
Occasional Contributor
10 years ago

Runtime Error when opening and closing Excel Spreadsheet continuously

Dear All,



     When I executing my project, I get intermittent runtime errors when opening and closing Excel Spreadsheet continuously. Below code I am using.





set xlobj= Sys.OleObject("Excel.Application")

Set workbookObj=xlobj.Workbooks.Open(Project.Path + "\Data_Input\Data_Input.xlsx")

Set wrksheetObjtest1=workbookObj.Worksheets(SheetName)


I saw a thread with same issue created in long back ago( http://smartbear.com/forums/f74/t53094/runtime-error-opening-excel-spreadsheet/ ) .



Thanks in advance!


.

1 Reply

  • If you're continuously opening and closing Excel, how are you closing it? Are you closing the active workbook or the Excel application? If you're closing Excel itself, it could be an issue of the process not closing before you try to open it again. If that's the case, you could use a sys.waitprocess("excel")  to make sure it's closed before moving on. Or, just close the workbook without closing Excel:

    workbookObj.close

     Then when you need to open a new workbook, you check for the existance of the process and if it's there, go straight to opening the workbook.