ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Disabling code using a button? (https://www.excelbanter.com/excel-programming/302259-disabling-code-using-button.html)

Simon Lloyd[_505_]

Disabling code using a button?
 
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

--
Message posted from http://www.ExcelForum.com


Berend Botje[_25_]

Disabling code using a button?
 
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

--
Message posted from http://www.ExcelForum.com


Simon Lloyd[_507_]

Disabling code using a button?
 
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

--
Message posted from http://www.ExcelForum.com


Ron de Bruin

Disabling code using a button?
 
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


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Simon Lloyd " wrote in message ...
Does anyone know how to stop all the code working in a workbook by
clickin an added button and then allowing the code to be active again
on the next click of that button?

Thanks!

Simon


---
Message posted from http://www.ExcelForum.com/




Simon Lloyd[_508_]

Disabling code using a button?
 
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

--
Message posted from http://www.ExcelForum.com


Berend Botje[_26_]

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

--
Message posted from http://www.ExcelForum.com


Ron de Bruin

Disabling code using a button?
 
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




--
Regards Ron de Bruin
http://www.rondebruin.nl


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

Simon


---
Message posted from http://www.ExcelForum.com/





All times are GMT +1. The time now is 01:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com