Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is there a way to close an xl file if the vbs terminates abnormally? 2

Status
Not open for further replies.

wvdba

IS-IT--Management
Jun 3, 2008
465
US
hi.
i have a vb script that normally runs ok. sometimes because of user errors, it terminates abnormally and the file stays open. then there's no way to close the xl file. the only way is to re-boot the machine. is there anyway to close the xl file after it has remained open by vbs abnormal termination?
thanks.
 



hi
sometimes because of user errors, it terminates abnormally ...
Then code some error handling to prevent this abnormal end from occurring!

Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
skipvought is correct, your script should just handle the errors.
but, you could close the excel doc later from a different script if you wanted to,

'#### Find existing instance of Excel
Set objApp = GetObject(, "Excel.Application")
 
thanks mrmovie.
the code has run for 6 months for over 400 files without any problems. the errors rate is less than a quarter of a percent. but, you're right, i'll work on that issue.
this line:
'#### Find existing instance of ExcelSet objApp = GetObject(, "Excel.Application")
what comes after this code?
a close?
or what?
thanks.
 
that gets you a ref to an open instance of Excel (or throws a run time if there isnt an open instance of Excel)
you could then do .quit which is pretty dirty. might be better to do an enumeration of all open excel workbooks with a save and a close, then .quit excel (i think it is .quit)
 
mrmovie,
SkipVought
thank you both for the suggestion for error handling.
the errors were being caused by blank rows at the beginning of the xl worksheet.
i coded an error handling routing that if the row is blank, then close the xl file, quit the script and not run the sql based on the input.
i tested with blank rows and i also kept a separate vbs suggested by mrmovie to grab an open instance of the xl app and close the worksheet and the file.
worked ok.
thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top