Disabling code using a button?

  • Thread starter Thread starter Simon Lloyd
  • Start date Start date
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
 
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
 
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
 
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
 
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
 
Just put the whole code in the code of the worksheet the button (and th
data) is on. It should work then
 
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top