473,324 Members | 2,257 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

[Error Handling] Run-time Error '9'

18
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:

Expand|Select|Wrap|Line Numbers
  1. Dim ArgObj, var1, var2, var3 
  2. Set ArgObj = WScript.Arguments 
  3. On Error Goto 0
  4. 'First parameter target file
  5. var1 = ArgObj(0) 
  6. 'Second parameter validation file
  7. var2 = ArgObj(1) 
  8. 'Third parameter macro
  9. var3 = ArgObj(2)
  10. Set objExcel1 = CreateObject("Excel.Application")
  11.  
  12. Set objWorkbook1 = objExcel1.Workbooks.Open(var1)
  13.  
  14. Set objWorkbook2 = objExcel1.Workbooks.Open(var2)
  15.     objExcel1.Run (var3)
  16.  
  17. Set    objExcel1 = Nothing
  18. set ArgObj = Nothing
  19.  
  20.  
  21.  
Thanks.
Aug 5 '11 #1
1 1556
irGed
18
Update: fixed the EXCEL.EXE at windows task manager but the Run-time error message prompt is still there.

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. On Error Resume Next
  4.  
  5. Dim ArgObj, var1, var2, var3 
  6. Set ArgObj = WScript.Arguments 
  7.  
  8. 'First parameter target file
  9. var1 = ArgObj(0) 
  10. 'Second parameter validation file
  11. var2 = ArgObj(1) 
  12. 'Third parameter macro
  13. var3 = ArgObj(2)
  14. Set objExcel1 = CreateObject("Excel.Application")
  15. objExcel1.DisplayAlerts = false
  16. Set objWorkbook1 = objExcel1.Workbooks.Open(var1)
  17.  
  18. Set objWorkbook2 = objExcel1.Workbooks.Open(var2)
  19.     objExcel1.Run (var3)
  20. 'On Error GoTo 0
  21. objWorkbook1.Save
  22. objExcel1.Quit
  23.  
  24. WScript.Echo "Error: " &  Err.Description
  25. Err.Clear
  26. Set    objExcel1 = Nothing
  27. set ArgObj = Nothing
  28.  
Aug 5 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: siliconwafer | last post by:
Hi All, I am using C on linux and performed a 1/0 operation i.e a divide by zero using integer variables/constants.it gives me a floating point exceptionand the program terminates. I want to...
4
by: vooose | last post by:
Is there any way to handle exceptions thrown by .NET classses? During runtime and at seemingly random times, exceptions similar to the ones shown at the base of this post are thrown. These errors...
3
by: Robert Rotstein | last post by:
It appears that exception handling at the top-most level of a C# program, in the static void Main() method, differs depending on whether the program is run in debug mode or not. That is, code such...
1
by: DKode | last post by:
I find myself writing repetitive functions for handling null values from my DB like so: Private Function SetDateNull(ByVal p_date As Object) As Date If (TypeOf (p_date) Is System.DBNull) Then...
4
by: Tad Marshall | last post by:
Hi, I'm having limited luck getting an ApplicationException to work right in my code. This is VB.NET, VS 2003, Windows XP SP2, .NET Framework 1.1. I thought it would be convenient to take...
6
by: Robin Riley | last post by:
Hi, I have a .NET solution that contains a dll project and a tester application project which, of course, invokes the dll. The dll project has exception handling in it. What's happening is that...
2
by: Jordan | last post by:
I need to handle UI events in a worker thread instead of the primary UI thread. In C#, is the normal UI event handling behavior to run in a context thread on the thread pool or are events always...
6
by: Joel | last post by:
2 Questions: (1) The documentation says application.run() creates a standard message loop on the current thread and "optionally" shows a form. This is really confusing because I was of the...
5
by: Bry | last post by:
I've created a class that offers an enhanced way of handling fatal exceptions. The class allows the user to optionaly submit a http based anonymous error report to myself, and also records details...
2
by: Joshua Kugler | last post by:
Standard disclaimer: read, googled, read some more. If you have a link, please free free to point me there. I'm using HTTPlib to construct some functional tests for a web app we're writing. ...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.