XLQuit not closing read-only Excel workbooks

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
SandyDoss
Junior Coder
Posts: 40
Joined: Wed Sep 07, 2016 12:47 am

XLQuit not closing read-only Excel workbooks

Post by SandyDoss » Tue Sep 13, 2016 10:28 pm

Hi,
I'm running through a script that creates a directory listing of *.xls* files. For each file found, I open with XLOpen (non-visible), pull and process some data, eventually closing that file with XLQuit. The files are created outside of my control, and are read-only files.

I'm running MacroScheduler currently on an XP sp3 machine using Microsoft Office 2003. The files I'm opening were created in a MUCH more recent version of excel (thus, .xlsx) but because of my older machine, the files are being run through a converter (I'm assuming something like a 'plug-in' so that older versions of Excel can open these files).

At any rate, I'm finding that the XLQuit is not closing the Excel files, and after a run, I have multiple instances of Excel running on my local machine.

Any suggestions? Script code is as follows:

Code: Select all

GetFileList>S:\customer\Southwest University\Robot project\credit transfers\*.xls*,ws-file-list,|
Separate>ws-file-list,|,ws-name-files
If>ws-name-files_count = 0
  MessageModal>No excel files to process, ending script
  GoTo>EndRoutine
endif
let>i=0
Repeat>i
  let>i=i+1
//open an xls file
  XLOpen>ws-name-files_%i%,0,ws-name-xl-handle
//pull the ssan, school, and term. remove - from ssan
  XLGetCell>ws-name-xl-handle,Sheet1,7,2,ws-no-ssan
  XLGetCell>ws-name-xl-handle,Sheet1,4,4,ws-name-school
  XLGetCell>ws-name-xl-handle,Sheet1,9,2,ws-date-term
//split the ssan into 3 parts - can't send '-' to diamondd
  MidStr>ws-no-ssan,1,3,ssan-1
  MidStr>ws-no-ssan,5,2,ssan-2
  MidStr>ws-no-ssan,8,4,ssan-3
//here, I'm looking at a screen in a rdp session, doing some comparisons, using data to inquire,
//all working appropriately.  At this point, then I need to loop through the .xls file I've just opened:
  wait>1
//now. start at row 16. while our course-id is not 'Total', find a blank hours cell, perform subroutine
  let>row=16
  let>ws-flag-first=Y
  XLGetCell>ws-name-xl-handle,Sheet1,row,1,ws-id-course
  while>ws-id-course<>Total
    XLGetCell>ws-name-xl-handle,Sheet1,row,3,ws-hours
    If>ws-hours<1
      Gosub>processCredits
    EndIf
    let>row=row+1
    XLGetCell>ws-name-xl-handle,Sheet1,row,1,ws-id-course
  EndWhile
  XLQuit>ws-name-xl-handle
Until>i,ws-name-files_count
The processCredits subroutine is simply sending data to a screen and entering records in the remote application. Again, all working. Thanks in advance for any suggestions :) -- Sandy

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: XLQuit not closing read-only Excel workbooks

Post by JRL » Wed Sep 14, 2016 4:17 am

You could throw in a KillProcess>Excel.exe after the XLQuit>. Or you could use something like the following to make sure you got 'em all.

Code: Select all

Label>KillExcels
ProcessExists>Excel.exe,ProcRes
If>ProcRes=True
  KillProcess>Excel.exe
  Wait>1
  Goto>KillExcels
EndIf

SandyDoss
Junior Coder
Posts: 40
Joined: Wed Sep 07, 2016 12:47 am

Re: XLQuit not closing read-only Excel workbooks

Post by SandyDoss » Wed Sep 14, 2016 2:55 pm

Super. Thanks much.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts