ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Toggle Switch (https://www.excelbanter.com/excel-programming/393302-toggle-switch.html)

Beep Beep

Toggle Switch
 
Bob gave me the following macro to switch from calculation auto to
calculation manual and works just fine. What I would like to next is to
change the color of the button from Red if manual to Green if automatic. Can
do?


Sub ToggleCalculation()
With Application
If .Calculation = xlCalculationManual Then
.Calculation = xlCalculationAutomatic
Else
.Calculation = xlCalculationManual
End If
End With
End Sub



PCLIVE

Toggle Switch
 
You'll need to know the name of your command button. The code below is
using "CommandButton3".

Sub ToggleCalculation()

If Application.Calculation = xlCalculationManual _
Then
With ActiveSheet.OLEObjects("CommandButton3").Object
.BackColor = &HFF00&
.Caption = "Auto"
.ForeColor = &H0&
End With
Application.Calculation = xlCalculationAutomatic
Else
With ActiveSheet.OLEObjects("CommandButton3").Object
.BackColor = &HFF&
.Caption = "Manual"
.ForeColor = &HFFFFFF
End With
Application.Calculation = xlCalculationManual
End If
End Sub


HTH,
Paul

"Beep Beep" wrote in message
...
Bob gave me the following macro to switch from calculation auto to
calculation manual and works just fine. What I would like to next is to
change the color of the button from Red if manual to Green if automatic.
Can
do?


Sub ToggleCalculation()
With Application
If .Calculation = xlCalculationManual Then
.Calculation = xlCalculationAutomatic
Else
.Calculation = xlCalculationManual
End If
End With
End Sub





Tim

Toggle Switch
 
What kind of button - control toolbox, or forms ?

Tim


"Beep Beep" wrote in message
...
Bob gave me the following macro to switch from calculation auto to
calculation manual and works just fine. What I would like to next is to
change the color of the button from Red if manual to Green if automatic.
Can
do?


Sub ToggleCalculation()
With Application
If .Calculation = xlCalculationManual Then
.Calculation = xlCalculationAutomatic
Else
.Calculation = xlCalculationManual
End If
End With
End Sub





Tom Ogilvy

Toggle Switch
 
It is impossible to see from your code what kind of cutton you are talking
about.

If from the forms toolbar, then no.

Why not use a toggle button from the control toolbox toolbar and then you
shouldn't have to change the color.

--
Regards,
Tom Ogilvy



"Beep Beep" wrote:

Bob gave me the following macro to switch from calculation auto to
calculation manual and works just fine. What I would like to next is to
change the color of the button from Red if manual to Green if automatic. Can
do?


Sub ToggleCalculation()
With Application
If .Calculation = xlCalculationManual Then
.Calculation = xlCalculationAutomatic
Else
.Calculation = xlCalculationManual
End If
End With
End Sub



Beep Beep

Toggle Switch
 
Custom Button with a smiley face on the toolbar

"Tim" wrote:

What kind of button - control toolbox, or forms ?

Tim


"Beep Beep" wrote in message
...
Bob gave me the following macro to switch from calculation auto to
calculation manual and works just fine. What I would like to next is to
change the color of the button from Red if manual to Green if automatic.
Can
do?


Sub ToggleCalculation()
With Application
If .Calculation = xlCalculationManual Then
.Calculation = xlCalculationAutomatic
Else
.Calculation = xlCalculationManual
End If
End With
End Sub






Rick Rothstein \(MVP - VB\)

Toggle Switch
 
Sub ToggleCalculation()
With Application
If .Calculation = xlCalculationManual Then
.Calculation = xlCalculationAutomatic
Else
.Calculation = xlCalculationManual
End If
End With
End Sub


All of the above subroutine's code can be replaced with this single line...

Sub ToggleCalculation()
Application.Calculation = (xlCalculationManual + xlCalculationAutomatic) - Application.Calculation
End Sub

Rick

Beep Beep

Toggle Switch
 
Thanks Rich, however I am trying to determine if I can have the button on the
toolbar (custom button) to change colors when the calculation changes from
manual to automatic or vice versus.

"Rick Rothstein (MVP - VB)" wrote:

Sub ToggleCalculation()
With Application
If .Calculation = xlCalculationManual Then
.Calculation = xlCalculationAutomatic
Else
.Calculation = xlCalculationManual
End If
End With
End Sub


All of the above subroutine's code can be replaced with this single line...

Sub ToggleCalculation()
Application.Calculation = (xlCalculationManual + xlCalculationAutomatic) - Application.Calculation
End Sub

Rick


Tom Ogilvy

Toggle Switch
 
No you can't. You might want to change the icon on the button.
--
Regards,
Tom Ogilvy


"Beep Beep" wrote:

Thanks Rich, however I am trying to determine if I can have the button on the
toolbar (custom button) to change colors when the calculation changes from
manual to automatic or vice versus.

"Rick Rothstein (MVP - VB)" wrote:

Sub ToggleCalculation()
With Application
If .Calculation = xlCalculationManual Then
.Calculation = xlCalculationAutomatic
Else
.Calculation = xlCalculationManual
End If
End With
End Sub


All of the above subroutine's code can be replaced with this single line...

Sub ToggleCalculation()
Application.Calculation = (xlCalculationManual + xlCalculationAutomatic) - Application.Calculation
End Sub

Rick



All times are GMT +1. The time now is 02:47 PM.

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