excel vba - Inconsistent VBA Error Message Box? -


it seems message box vba pops-up when unhandled exception occurs behaves differently depending on... something? see mean, create new .xlsm, then create standard module module1; paste inside code paste inside sheet1 worksheet object code:

public sub testerrmsgbox()     debug.print "hello!"     call err.raise(number:=vbobjecterror, source:="vbaproject.sheet1",  description:="lorem ipsum") end sub 

on excel 2010 professional plus, calling subroutine in vbe's "immediate" (ctrl+g) window:

call module1.testerrmsgbox
call sheet1.testerrmsgbox 

will show error message automation error / invalid oleverb structure.

now, if 1 calls directly raise method in "immediate" window:

call err.raise(number:=vbobjecterror, source:="vbaproject.sheet1",  description:="lorem ipsum") 

it show (expected) error message lorem ipsum.

what changes in error handling, or in err object, first case last? , how may manipulated? figured out in first case message depends on number argument in raise call, still doesn't explain...

i find bit annoying, because expected messages displayed, not else. there's available pokemon approach (catching exceptions , showing custom messageboxes based on err properties), i'd understand happens. :-)

later edit:

the behavior described above happens when "error trapping" set on "break on unhandled errors." once put "break on errors" displays correct message, "debug" button available; however, not idea, break execution on every error...

also, feedback alex k., roryap , doug glancy figured out happens when testerrmsgbox subroutine called within worksheet object, not standard module incorrectly reported first time. posting fixed; however, question still there. :-)

the reason happens when sub in sheet module , you've set vbe break on unhandled errors, has fact sheet module class module. set error trapping break in class modules, , behave correctly.

i use setting anyways, can debug inside userforms , classes.

searching "vba err.raise invalid oleverb structure break in class module" seems support fact it's related class modules.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -