Richard
Mon Jan 28 08:36:53 CST 2008
<adam.at.prisma@gmail.com> wrote in message
news:99b457bb-3920-4361-86fa-54c54f0c2325@y5g2000hsf.googlegroups.com...
> Hi,
>
> I am writing a script that takes a file name on the command line and
> then tries to open the file and runs a macro in the file. I'm a newbie
> on VBscript btw.
>
> The problems:
>
> 1)
> If the user supplies a file name that does not exist, the script
> prints some error message to the command line, but the Excel object
> does not disappear.
>
> If I try this 10 times, 10 EXCEL.exe processes will show up in the
> task manager. Is there any way to have any unclosed handles/objects to
> be cleaned up automatically in the case of errors?
>
> 2)
> Some excel files asks for links to be updated with a message box, but
> I want this to run noninteractively and always want to "not update",
> can this behaviour be set in the script?
>
> Best Regards,
> Adam
Also, you can trap the possible error with "On Error Resume Next", deal with
the error by quitting Excel, then restore normal error handling. For
example:
============
strExcelPath = "c:\MyFolder\Groups.xls"
' Open specified spreadsheet and select the first worksheet.
On Error Resume Next
objExcel.WorkBooks.Open strExcelPath
If (Err.Number <> 0) Then
On Error GoTo 0
Wscript.Echo "Spreadsheet not found"
objExcel.Application.Quit
Wscript.Quit
End If
On Error GoTo 0
' Continue...
========
If an error is raised later that requires you to abort, then if you trap the
error you can also close the workbook before quitting.
=========
objExcel.ActiveWorkbook.Close
objExcel.Application.Quit
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab -
http://www.rlmueller.net
--