Welcome to the VanDyke Software Forums

Join the discussion today!


Go Back   VanDyke Software Forums > Scripting

Notices

Reply
 
Thread Tools Rate Thread Display Modes
  #1  
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)
Code:
On Error Resume Next
(Inside Main):

Code:
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:
Code:
objWkBook.Save
SbCleanUp g_objExcel


if err.Number <> 0 then
    SbCleanUp g_objExcel
    WScript.echo err.Description
    err.clear
    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
        g_objExcel.Quit
    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?

Thanks!
Reply With Quote
  #2  
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
__________________
--Todd

VanDyke Software
Technical Support
support@vandyke.com
505-332-5730
Reply With Quote
  #3  
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
Reply

Tags
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.