VBA Can i make a Emergency Stop button for code?

NessPJ

Active Member
Joined
May 10, 2011
Messages
414
Office Version
  1. 365
Hi all,

Does anyone know if it is possible to make a button on my excel sheet that will instantly stop all routines that are active?

I have a piece of code that also executes at a set interval of # minutes (posted below). This does not seem to stop when i press CTRL+Break. I have to run a routine with "Schedule:=False".

But i would also really like to add Button on my Excel sheet that allows the user to click it in case of 'emergency'. Is this possible?

VBA Code:
    RunWhen = Now + TimeSerial(0, RunInterval, 0)
    Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, _
    Schedule:=True                  'cRunWhat is a Public Const
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try this

VBA Code:
Public Const cRunWhat = "test"
Public RunWhen

Sub test()
  RunInterval = 1   'The number of minutes you want
  RunWhen = Now + TimeSerial(0, RunInterval, 0)                                   'RunWhen is a Public Variable
  Application.OnTime EarliestTime:=RunWhen, Procedure:=cRunWhat, Schedule:=True   'cRunWhat is a Public Const
End Sub

Sub stopEmergency()
  On Error Resume Next
  Application.OnTime RunWhen, cRunWhat, , False
End Sub
 
Upvote 0
Is there also a way or function to suddenly stop any (sub)routine that is currently being executed?
Each subroutine must have a way to exit.
You can interrupt a running macro by pressing the Break key.

Also check the following:
 
Upvote 0

Forum statistics

Threads
1,213,490
Messages
6,113,957
Members
448,535
Latest member
alrossman

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top