Pause or Stop a Macro Using Button

Eire75

New Member
Joined
Feb 23, 2008
Messages
19
Hi,

I have a macro working which activates a worksheet, updates the data in the worksheet (data is pulled in from an external database) and then moves on to the next worksheet and does the same. The macro loops so that it constantly indexes through every worksheet, updating the data being pulled from an external source as it goes.

Here is the code:

Code:
Sub Carousel()
 
  Dim ws As Worksheet
 
  Do
    For Each ws In ThisWorkbook.Worksheets
      ws.Activate
      Calculate
      Application.Wait Now() + TimeValue("00:00:08")
      DoEvents
    Next ws
  Loop
End Sub

I am using the 'Calculate' line to update the data pull.

What I would like to be able to do is insert two buttons on each worksheet - one to pause the macro as shown above, and one to reume it.

The data which is pulled in (every 8 seconds as per the code above) will be monitored and if something looks out of sorts, the observer needs to be able to 'freeze' what he or she is looking at, make some decisions and then reume monitoring the data as it updates every 8 seconds.

Simple as it may sound, I am unable to find anything which might help. Most other solutions involve user inputs or pauses capable of detecting when calculations are complete. I simply want to be able to click a button to pause and then click another to resume a macro.

Any help would be greatly appreciated.

Thanks in advance,

Eire75.
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
You might consider using the Application.OnTime method rather than Application.Wait. That way you could tie a button to a simple macro that sets the schedule parameter for OnTime to false to stop the cycling. Another button to start your Carousel macro again.
 
Upvote 0

Forum statistics

Threads
1,224,602
Messages
6,179,845
Members
452,948
Latest member
UsmanAli786

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