Forum Discussion
lrbehmer
13 years agoContributor
Ah. Yes, the F drive is a partition we're all using locally so our SVN mapping is the same. Thing is, we've been using this for several months and my machine is the only one experiencing the issue. I'll look into it.
We've always closed Excel using the quit() or close() methods and haven't had any problems until now. I'll try out your suggestions and see what happens. I'd be willing to bet that the Excel process just hasn't fully closed before the next script runs.
Thanks.
-=[EDIT]=-
Bingo. I added this bit of code before starting Excel again and it works like a charm. Might even solve an issue putting Excel operations into a Runtime Object not closing Excel.
// Check for pre-existing Excel and kill it if it exists:
var old_excel = Sys.WaitProcess("excel", 100) ;
if(old_excel.Exists)
{
if (!old_excel.Close())
{
Log.Warning("Excel was not closed successfully and will be terminated.") ;
// Terminate Excel:
old_excel.Terminate() ;
}
}
We've always closed Excel using the quit() or close() methods and haven't had any problems until now. I'll try out your suggestions and see what happens. I'd be willing to bet that the Excel process just hasn't fully closed before the next script runs.
Thanks.
-=[EDIT]=-
Bingo. I added this bit of code before starting Excel again and it works like a charm. Might even solve an issue putting Excel operations into a Runtime Object not closing Excel.
// Check for pre-existing Excel and kill it if it exists:
var old_excel = Sys.WaitProcess("excel", 100) ;
if(old_excel.Exists)
{
if (!old_excel.Close())
{
Log.Warning("Excel was not closed successfully and will be terminated.") ;
// Terminate Excel:
old_excel.Terminate() ;
}
}
- ory_z9 years agoContributor
Thanks lrbehmer for the solution to the problem!
I find it happens when connecting with the Excel OLE object more than once.
Your solution works but it has the side effect of closing all open excel worksheets on the computer. Strangely enough I found out it is enough to just access the running process to avoid the issue e.g.
Set old_excel = Sys.WaitProcess("excel", 100)
Working code (VBScript):
Sub UseExcelInSomeWay(workbook, sheetName) Dim app, old_excel 'Handle Runtime error when accessing excel more than once - http://community.smartbear.com/t5/Getting-Started-with/Runtime-Error-opening-Excel-Spreadsheet/td-p/48290 Set old_excel = Sys.WaitProcess("excel", 100) ' Set Excel App Set app = Sys.OleObject("Excel.Application") Set book = app.Workbooks.Open(workbook) Set sheet = book.Sheets(sheetName) app.DisplayAlerts = False ' Excel code here ... book.Close End Sub