Disabling code using a button?

S

Simon Lloyd

Does anyone know how to stop all the code working in a workbook b
clickin an added button and then allowing the code to be active agai
on the next click of that button?

Thanks!

Simo
 
B

Berend Botje

That is not too hard....

Public StartStopCode As Boolean

Private Sub Button_Click()

If StartStopCode = True Then
StartStopCode = False
Else: StartStopCode = True
End If

End Sub

Private Sub MyCode()
If StartStopCode = False Then

' Your code here

End If
End Su
 
S

Simon Lloyd

Thanks Berend, but im fairly new to this and the first part of the cod
looks like a loop startstopcode=True Then startstopcode=False, als
where do i put this?...in the Thisworkbook code?

Hope you can advise.

Simo
 
R

Ron de Bruin

One way is to add a macro to the button that will put "No"
in cell A1 for example

Sub test()
With Sheets("Sheet1").Range("A1")
If .Value = "No" Then
.Value = "Yes"
Else
.Value = "No"
End If
End With
End Sub

And in all your other macro's add this line at the top
If Sheets("Sheet1").Range("A1").Value = "No" Then Exit Sub
 
S

Simon Lloyd

Ron Can that .Value=0 be in any cell i choose, need the code to b
disabled because i have a lot of worksheet selection_change code s
when on the spread sheet you try to drag and select rows and or column
the events try to take place and crash the program thats why i need t
add a button to the menubar that turns of this code until presse
again!

Simo
 
B

Berend Botje

Just put the whole code in the code of the worksheet the button (and th
data) is on. It should work then
 
R

Ron de Bruin

Ron Can that .Value=0 be in any cell i choose
yes you can choose the cell

You can disable events like this also
Application.EnableEvents = False
 
Top