Welcome to the VanDyke Software Forums

Join the discussion today!

Go Back   VanDyke Software Forums > Scripting


Thread Tools Rate Thread Display Modes
Old 01-12-2015, 08:07 AM
redespace redespace is offline
Registered User
Join Date: Oct 2014
Posts: 12
Question Close excel.exe when stopping script

Hi Guys,

I have 2 different scripts that use Excel to read and write data from SecureCRT. The problem I am having is that in case I cancel the running script, Excel.exe stays in the background. I searched Google and found a solution, but its only when getting run time errors, and not stopping script.

I tried:
(before Main)
On Error Resume Next
(Inside Main):

crt.Screen.Synchronous = True
Dim g_objExcel
Set g_objExcel = CreateObject("Excel.Application")
Dim objWkBook
Set objWkBook = g_objExcel.Workbooks.Open(g_strSpreadSheetPath)
Dim objSheet
Set objSheet = objWkBook.Sheets(1)
And at the end:
SbCleanUp g_objExcel

if err.Number <> 0 then
    SbCleanUp g_objExcel
    WScript.echo err.Description
    WScript.Quit 1
end if

Sub SbCleanUp(byref g_objExcel)
    if not (g_objExcel Is Nothing) then
        dim objWkBook
        for each objWkBook in g_objExcel.WorkBooks
            objWkBook.Saved = true
        next 'objWkBook
    end if
End Sub

It seems to be working when a run time error happens (e.g.: Excel workbook not found), but it doesn't work when I manually cancel the script.

Is there a way I can achieve this?
Maybe have a timeout when creating the Excel.Application process? or maybe having SecureCRT manually inject an exception to the running script?

Reply With Quote
Old 01-12-2015, 04:06 PM
rtb rtb is offline
VanDyke Technical Support
Join Date: Aug 2008
Posts: 4,305
Hi redespace,

Currently, SecureCRT just closes a script when told to do so. It doesn't have a way to try and rollback things that might have taken place (especially if they are external like using the Excel object).

You may consider modifying your script to gather all of the data you want to write to the spreadsheet prior to creating the Excel object.

We will post to this forum thread if that type of functionality is added to a future SecureCRT release.

If you would like to be notified directly, please complete and submit the form at the following location:
Submit Feature Request

VanDyke Software
Technical Support
Reply With Quote
Old 01-20-2015, 05:56 AM
redespace redespace is offline
Registered User
Join Date: Oct 2014
Posts: 12
Thank you Todd for the reply.

I will hope that in the future releases they have this feature. Quite useful, to inject error code to the script or to have a Button that exits the Sub (or smthing)
Reply With Quote

close excel.exe , ghost excel.exe , stop script

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -6. The time now is 11:20 AM.