PDA

View Full Version : trapping error



lior03
01-18-2006, 12:07 AM
hello
i took johnske article about error seriously - as always.
the following macro works in excel xp at home but fail to do so in excel 2000
at work.

Sub sumsum()
On Error GoTo MyErrHandler
Dim x As Long
Dim y As Long
x = InputBox("number one")
y = InputBox("number two")
MsgBox " result is " & Divide(x, y)
Exit Sub
MyErrHandler:
MsgBox "sorry !!! error " & ERR.number & "-" & ERR.Description, vbExclamation
End Sub


by failng i mean i dont see the errorhandler work.i get the usual "crash" msgbox.
any suggestions guys !
thanks

Bob Phillips
01-18-2006, 03:09 AM
I just tested it with 2000 and it works fine for me. I tried a text value in either box, and both trapped okay.

johnske
01-18-2006, 03:14 AM
Hi Moshe,

That works fine for me (Office2000, WIn98) except for the Divide(x, y) which I had to replace with x / y - what versions of office are you using on the two machines?

Regards,
John

lior03
01-18-2006, 03:45 AM
office xp hebrew

office 2000 hebrew

johnske
01-18-2006, 06:19 AM
office xp hebrew

office 2000 hebrewWell I think the different versions may be the major part of the problem. My Office 2000 doesn't recognize 'Divide(x, y)' and throws an error, obviously office xp does recognize it (but 2000 doesn't) so try the earlier x / y as a replacement for it on both machines and see if that works. :)

EDIT: Or are you using a "Divide" function that you haven't mentioned or put in your code above? (Not having a later version of office I don't know if a Divide function is an inherent part of it or not)

Bob Phillips
01-18-2006, 08:04 AM
Well I think the different versions may be the major part of the problem. My Office 2000 doesn't recognize 'Divide(x, y)' and throws an error, obviously office xp does recognize it (but 2000 doesn't) so try the earlier x / y as a replacement for it on both machines and see if that works. :)

EDIT: Or are you using a "Divide" function that you haven't mentioned or put in your code above? (Not having a later version of office I don't know if a Divide function is an inherent part of it or not)

Divide must be a function, XP doesn't recognise it.

lior03
02-03-2006, 01:19 AM
hello john
you wrote a great essay on error trapping in excel vba at www.vbaexpress.com (http://www.vbaexpress.com/). it was very good and usefull.
a question bothered me for weeks - how to enable the user built his own error message.
i found the answer which i think should be part of your essay.
in his great book excel 2000 programming with vba - page 237 - john walkenbach explains that a user should turn off his break on all errors setting. instead he say a user must thick break on unhandled error option.in vba -tools-options
please make it part of your article for the benefit of laymen like me.
yours
moshe