Error handling

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
jsmyong55
Newbie
Posts: 18
Joined: Thu Aug 29, 2013 4:14 am

Error handling

Post by jsmyong55 » Tue Sep 03, 2013 3:07 pm

Hi, So far you guys have been really awesome in helping me out with my MS problems. My program currently calls an Excel file to read from it. Before I call it, I will have a task kill function to kill any running excel tasks. I will call it again at the end to make sure any excel tasks are closed. However, during debugging, say if the program stops in the middle while running, with the Excel file open, it will show an error the next time I run it. This is because Excel has not been properly shut down and is still running in the background. I would then have to manually open Task Manager to end it before I start to prevent the error from occuring. The error goes like this "Microsoft VBScript runtime error:424 Object required 'xlApp'.

My question is, how do I perform error handling to ensure that if an error like this occurs, to immediately issue a Kill task command?[/img]

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Tue Sep 03, 2013 10:13 pm

I'm not sure this is possible. Macro Scheduler processes script lines sequentially so I would think that when the script crashes any error handling would cease as well.

For convenience I would suggest creating another script that closes any process named "excel". Assign a hot key to that script and when your program crashes during debug all you need to do is press the hot key combination to close all instances of excel.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 1390
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Post by Dorian (MJT support) » Tue Sep 03, 2013 10:34 pm

JRL wrote: For convenience I would suggest creating another script that closes any process named "excel". Assign a hot key to that script and when your program crashes during debug all you need to do is press the hot key combination to close all instances of excel.
And/Or use a Window Event Trigger to watch out for the error popup?
Yes, we have a Custom Scripting Service. Message me or go here

rullbandspelare
Pro Scripter
Posts: 149
Joined: Tue Mar 23, 2004 9:11 pm

Post by rullbandspelare » Fri Jan 31, 2014 2:44 pm

Would it be possible to have the compiled makro terminate (Abort as default option) instead of throwing a Information window?

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Feb 03, 2014 4:00 pm

I guess you could use VBScript error trapping and return a value to the function and then check that value after VBEval and then if you want to terminate use the Exit command.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

jsmyong55
Newbie
Posts: 18
Joined: Thu Aug 29, 2013 4:14 am

Post by jsmyong55 » Mon Feb 10, 2014 6:26 am

What about error handling for corrupted files? Currently if a db query is running and it encounters a file that is corrupted and cannot be opened, it will hang. I would like for it to be able to log the file that is corrupted and skip that file and resume running the query. If anyone is willing to provide professional services to help me with this issue, please pm me.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts