[Error Handling] Run-time Error '9'

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • irGed
    New Member
    • Jul 2011
    • 18

    #1

    [Error Handling] Run-time Error '9'

    Hi,

    I am trying to add an error handling functionality on my vbscript, but it doesnt seem working. My vbscript simply invokes an Excel Macro but there are some instance that the macro will produce a runtime error and when it happens, a message box prompts saying a Runtime error and then an "EXCEL.EXE" is running at my Windows Task Manager. I wanted to get rid of those two (EXCEL.EXE at task manager and Runtime error prompt message). How can I do that?

    My sample code is as follows and I am executing this script using the "cscript" function:

    Code:
    Dim ArgObj, var1, var2, var3 
    Set ArgObj = WScript.Arguments 
    On Error Goto 0
    'First parameter target file
    var1 = ArgObj(0) 
    'Second parameter validation file
    var2 = ArgObj(1) 
    'Third parameter macro
    var3 = ArgObj(2)
    Set objExcel1 = CreateObject("Excel.Application")
    
    Set objWorkbook1 = objExcel1.Workbooks.Open(var1)
    
    Set objWorkbook2 = objExcel1.Workbooks.Open(var2)
    	objExcel1.Run (var3)
    
    Set	objExcel1 = Nothing
    set ArgObj = Nothing
    Thanks.
  • irGed
    New Member
    • Jul 2011
    • 18

    #2
    Update: fixed the EXCEL.EXE at windows task manager but the Run-time error message prompt is still there.

    Code:
    
    On Error Resume Next
    
    Dim ArgObj, var1, var2, var3 
    Set ArgObj = WScript.Arguments 
    
    'First parameter target file
    var1 = ArgObj(0) 
    'Second parameter validation file
    var2 = ArgObj(1) 
    'Third parameter macro
    var3 = ArgObj(2)
    Set objExcel1 = CreateObject("Excel.Application")
    objExcel1.DisplayAlerts = false
    Set objWorkbook1 = objExcel1.Workbooks.Open(var1)
    
    Set objWorkbook2 = objExcel1.Workbooks.Open(var2)
    	objExcel1.Run (var3)
    'On Error GoTo 0
    objWorkbook1.Save
    objExcel1.Quit
    
    WScript.Echo "Error: " &  Err.Description
    Err.Clear
    Set	objExcel1 = Nothing
    set ArgObj = Nothing

    Comment

    Working...