Reset status bar if a macro returns an error Excel VBA -
i'm using application.statusbar update status of macro runs. beacuse have screenupdating turned off.
now if stop macro during process or if encounters kind of error status bar stays @ last set gives appearance of program still running.
is there way reset status bar @ such occurance?
i use this:
sub gracefulexit() dim errmsg string on error goto ender: application.calculation = xlcalculationmanual application.screenupdating = false application.enableevents = false application.statusbar = "running gracefulexit" err = 1004 'set error invoke ender: ender: 'this defy indentation in module - stays in col 1 if err <> 0 'display error errmsg = "an unexpected error has occured:" & vbcrlf & vbcrlf _ & vbtab & "error no: " & err & vbcrlf _ & vbtab & "description: " & error & vbcrlf _ & vbtab & "statusbar was: """ & application.statusbar & """" msgbox errmsg, vbcritical end if 'otherwise reset application settings application.calculation = xlcalculationautomatic application.enableevents = true application.statusbar = "" application.screenupdating = true end sub
the various settings provided examples of may want manipulate. may want test , store application.calculation status before set xlmanual in case user has set xlmanual - annoyed if reset xlautomatic!
the important thing application.screenupdating = false, application.statusbar can changed code executes. when click ok on message box, statusbar revert its' "normal" state.
Comments
Post a Comment