As the title suggests, does anyone have a solution to this problem? It's completely crazy having to kill the Excel task from the command line or task manager just to stop code from running!
Stopping a VBA loop that contains a dialog box!
If I force that error and click on "OK" it opens the source in debug mode at the bad line as if there was a breakpoint there.
My VB | Tools | Options has "break on unhandled errors" (Excel 365) ...
My VB | Tools | Options has "break on unhandled errors" (Excel 365) ...
You do not have the required permissions to view the files attached to this post.
I assume you are testing code, this is just an idea, it may help you, but without seeing the code that forces this Message Box to be called, it is difficult to see what is happening, but you could try adding
Application.DisplayAlerts = False
at the start of the loop in your code, I think it should but I am not 100 percent certain if it will work in your circumstances.
do not forget to add
Application.DisplayAlerts = True
after the end of your loop.
You may have to use Application.EnableEvents = False and Application.EnableEvents = True as well.
Hopefully this should stop multiple system message boxes appearing, like you have had whilst testing code, however you will need to collect error information yourself and resume next on errors.
Application.DisplayAlerts = False
at the start of the loop in your code, I think it should but I am not 100 percent certain if it will work in your circumstances.
do not forget to add
Application.DisplayAlerts = True
after the end of your loop.
You may have to use Application.EnableEvents = False and Application.EnableEvents = True as well.
Hopefully this should stop multiple system message boxes appearing, like you have had whilst testing code, however you will need to collect error information yourself and resume next on errors.
Actually, it wasn't a loop, although the problem can occur when a dialog box appears in a loop. I changed some code while it was running that produced a compile error. I've seen in places you can stop code by pressing CTRL + BREAK, but neither of my PCs have a break key and I'm not sure that would work when you've got a dialog box on the screen.conduirez wrote: ↑Fri Nov 24, 2023 12:22 amI assume you are testing code, this is just an idea, it may help you, but without seeing the code that forces this Message Box to be called, it is difficult to see what is happening, but you could try adding
Application.DisplayAlerts = False
at the start of the loop in your code, I think it should but I am not 100 percent certain if it will work in your circumstances.
do not forget to add
Application.DisplayAlerts = True
after the end of your loop.
You may have to use Application.EnableEvents = False and Application.EnableEvents = True as well.
Hopefully this should stop multiple system message boxes appearing, like you have had whilst testing code, however you will need to collect error information yourself and resume next on errors.
If the sub or func that it's throwing that error at does exist there's a chance that the code module could have become corrupted during compilation. Can happen from time to time.
When it does I create a new code module inside the file, copy all of the code from the offending module, delete the original then rename the new module to what it had been
I always have Option Explicit set as well (Tools -> Options -> Editor -> Require Variable Declaration)
Try running a debug -> Compile VBA Project which should also take you to where there is any offending code as well.
When it does I create a new code module inside the file, copy all of the code from the offending module, delete the original then rename the new module to what it had been
I always have Option Explicit set as well (Tools -> Options -> Editor -> Require Variable Declaration)
Try running a debug -> Compile VBA Project which should also take you to where there is any offending code as well.
You can't do that with a dialog box on the screen. All you can do is click on OK, and as it's in a loop it immediately reappears.ODPaul82 wrote: ↑Fri Nov 24, 2023 5:53 amIf the sub or func that it's throwing that error at does exist there's a chance that the code module could have become corrupted during compilation. Can happen from time to time.
When it does I create a new code module inside the file, copy all of the code from the offending module, delete the original then rename the new module to what it had been
I always have Option Explicit set as well (Tools -> Options -> Editor -> Require Variable Declaration)
Try running a debug -> Compile VBA Project which should also take you to where there is any offending code as well.
There is one chance that pressing and holding down the 'esc' key may work in your case. If this does not work try to hit the 'esc' key twice quickly. Apart from that I am out of ideas.
For reference, I know on Dell models the substitute for 'ctrl' - 'break'' is pressing 'ctrl' - 'fn' - 'B' keys together, but with a dialogue box that keeps repeating this will not work.
Another thing to check before your code runs is that all your references are still ticked.
For reference, I know on Dell models the substitute for 'ctrl' - 'break'' is pressing 'ctrl' - 'fn' - 'B' keys together, but with a dialogue box that keeps repeating this will not work.
Another thing to check before your code runs is that all your references are still ticked.
Run the On-Screen Keyboard (Windows key + R and type the program name osk) that has a Ctrl and Pause/Scroll keys.
Not sure if it will work though since CtrlBrk has a special scancode !
On the physical keyboard Ctrl + NumLock / Ctrl + ScrLock used to work for Pause / Break respectively on small layout keyboards back in the day - may work.
Not sure if it will work though since CtrlBrk has a special scancode !
On the physical keyboard Ctrl + NumLock / Ctrl + ScrLock used to work for Pause / Break respectively on small layout keyboards back in the day - may work.