Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Toggle Calc button - working, but want it showing "depressed"
Thanks for all help. I was able to get the Toggle Calc .xla add-in working
with the following code. However, I can't figure out how to change this macro to be "depressed" when Calc is ON, and "pushed up" when the Calc is OFF. Any help? I cannot get msoButtonUp, msoButtonDown, and .State to work at all. Thanks! **** IN THE MODULE'S VBA **** Sub ToggleApplicationCalculation() On Error GoTo ErrorHandler If Application.Calculation = xlManual Then Application.Calculation = xlAutomatic MsgBox "Calculation toggled to Automatic." Else Application.Calculation = xlManual Application.CalculateBeforeSave = True MsgBox "Calculation toggled to Manual." End If ErrorHandler: End Sub 'ToggleApplicationCalculation **** IN THISWORKBOOK'S VBA **** Private Sub Workbook_BeforeClose(Cancel As Boolean) On Error Resume Next Application.CommandBars("Standard").Controls( _ "ToggleApplicationCalculation").Delete On Error GoTo 0 End Sub Private Sub Workbook_Open() On Error Resume Next Application.CommandBars("Standard").Controls( _ "ToggleApplicationCalculation").Delete On Error GoTo 0 With Application.CommandBars("Standard") With .Controls.Add(Temporary:=True) .BeginGroup = True .Style = msoButtonIcon .FaceId = 283 .Caption = "CalculateToggle" .OnAction = "ToggleApplicationCalculation" End With End With End Sub |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Toggle Calc button - working, but want it showing "depressed"
Hi Mike,
The following worked for me: '=============================== Sub ToggleApplicationCalculation() With Application.CommandBars.ActionControl If .State = msoButtonUp Then .State = msoButtonDown Else .State = msoButtonUp End If End With On Error GoTo ErrorHandler If Application.Calculation = xlManual Then Application.Calculation = xlAutomatic MsgBox "Calculation toggled to Automatic." Else Application.Calculation = xlManual Application.CalculateBeforeSave = True MsgBox "Calculation toggled to Manual." End If ErrorHandler: End Sub 'ToggleApplicationCalculation Private Sub Workbook_BeforeClose(Cancel As Boolean) On Error Resume Next Application.CommandBars("Standard").Controls( _ "ToggleApplicationCalculation").Delete On Error GoTo 0 End Sub '<<=============================== '=============================== Private Sub Workbook_BeforeClose(Cancel As Boolean) On Error Resume Next Application.CommandBars("Standard").Controls( _ "ToggleApplicationCalculation").Delete On Error GoTo 0 End Sub '<<=============================== =============================== Private Sub Workbook_Open() On Error Resume Next Application.CommandBars("Standard").Controls( _ "ToggleApplicationCalculation").Delete On Error GoTo 0 With Application.CommandBars("Standard") With .Controls.Add(Temporary:=True) .BeginGroup = True .Style = msoButtonIcon .FaceId = 283 .Caption = "CalculateToggle" .State = msoButtonUp .OnAction = "ToggleApplicationCalculation" End With End With End Sub '<<=============================== --- Regards, Norman "Mike" wrote in message ... Thanks for all help. I was able to get the Toggle Calc .xla add-in working with the following code. However, I can't figure out how to change this macro to be "depressed" when Calc is ON, and "pushed up" when the Calc is OFF. Any help? I cannot get msoButtonUp, msoButtonDown, and .State to work at all. Thanks! **** IN THE MODULE'S VBA **** Sub ToggleApplicationCalculation() On Error GoTo ErrorHandler If Application.Calculation = xlManual Then Application.Calculation = xlAutomatic MsgBox "Calculation toggled to Automatic." Else Application.Calculation = xlManual Application.CalculateBeforeSave = True MsgBox "Calculation toggled to Manual." End If ErrorHandler: End Sub 'ToggleApplicationCalculation **** IN THISWORKBOOK'S VBA **** Private Sub Workbook_BeforeClose(Cancel As Boolean) On Error Resume Next Application.CommandBars("Standard").Controls( _ "ToggleApplicationCalculation").Delete On Error GoTo 0 End Sub Private Sub Workbook_Open() On Error Resume Next Application.CommandBars("Standard").Controls( _ "ToggleApplicationCalculation").Delete On Error GoTo 0 With Application.CommandBars("Standard") With .Controls.Add(Temporary:=True) .BeginGroup = True .Style = msoButtonIcon .FaceId = 283 .Caption = "CalculateToggle" .OnAction = "ToggleApplicationCalculation" End With End With End Sub |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Toggle Calc button - working, but want it showing "depressed"
This worked great. One last request -- is there a way to get this to work
when Excel is first opened? I tried several things, but not working. I am wondering if this is because it happens before Excel worksheets are open. "Norman Jones" wrote: Hi Mike, The following worked for me: '=============================== Sub ToggleApplicationCalculation() With Application.CommandBars.ActionControl If .State = msoButtonUp Then .State = msoButtonDown Else .State = msoButtonUp End If End With On Error GoTo ErrorHandler If Application.Calculation = xlManual Then Application.Calculation = xlAutomatic MsgBox "Calculation toggled to Automatic." Else Application.Calculation = xlManual Application.CalculateBeforeSave = True MsgBox "Calculation toggled to Manual." End If ErrorHandler: End Sub 'ToggleApplicationCalculation Private Sub Workbook_BeforeClose(Cancel As Boolean) On Error Resume Next Application.CommandBars("Standard").Controls( _ "ToggleApplicationCalculation").Delete On Error GoTo 0 End Sub '<<=============================== '=============================== Private Sub Workbook_BeforeClose(Cancel As Boolean) On Error Resume Next Application.CommandBars("Standard").Controls( _ "ToggleApplicationCalculation").Delete On Error GoTo 0 End Sub '<<=============================== =============================== Private Sub Workbook_Open() On Error Resume Next Application.CommandBars("Standard").Controls( _ "ToggleApplicationCalculation").Delete On Error GoTo 0 With Application.CommandBars("Standard") With .Controls.Add(Temporary:=True) .BeginGroup = True .Style = msoButtonIcon .FaceId = 283 .Caption = "CalculateToggle" .State = msoButtonUp .OnAction = "ToggleApplicationCalculation" End With End With End Sub '<<=============================== --- Regards, Norman "Mike" wrote in message ... Thanks for all help. I was able to get the Toggle Calc .xla add-in working with the following code. However, I can't figure out how to change this macro to be "depressed" when Calc is ON, and "pushed up" when the Calc is OFF. Any help? I cannot get msoButtonUp, msoButtonDown, and .State to work at all. Thanks! **** IN THE MODULE'S VBA **** Sub ToggleApplicationCalculation() On Error GoTo ErrorHandler If Application.Calculation = xlManual Then Application.Calculation = xlAutomatic MsgBox "Calculation toggled to Automatic." Else Application.Calculation = xlManual Application.CalculateBeforeSave = True MsgBox "Calculation toggled to Manual." End If ErrorHandler: End Sub 'ToggleApplicationCalculation **** IN THISWORKBOOK'S VBA **** Private Sub Workbook_BeforeClose(Cancel As Boolean) On Error Resume Next Application.CommandBars("Standard").Controls( _ "ToggleApplicationCalculation").Delete On Error GoTo 0 End Sub Private Sub Workbook_Open() On Error Resume Next Application.CommandBars("Standard").Controls( _ "ToggleApplicationCalculation").Delete On Error GoTo 0 With Application.CommandBars("Standard") With .Controls.Add(Temporary:=True) .BeginGroup = True .Style = msoButtonIcon .FaceId = 283 .Caption = "CalculateToggle" .OnAction = "ToggleApplicationCalculation" End With End With End Sub |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Toggle Calc button - working, but want it showing "depressed"
Hi Mike,
You need to correct two errors in your original code. In both the workbook_Open and Workbook_BeforeClose procedures, changE: Application.CommandBars("Standard").Controls( _ "ToggleApplicationCalculation").Delete to: Application.CommandBars("Standard").Controls( _ "CalculateToggle").Delete (The control's caption was incorrect) With these amendments, the toolbar button is added when the workbook opens and is removed when the workbook is closed. --- Regards, Norman "Mike" wrote in message ... This worked great. One last request -- is there a way to get this to work when Excel is first opened? I tried several things, but not working. I am wondering if this is because it happens before Excel worksheets are open. "Norman Jones" wrote: Hi Mike, The following worked for me: '=============================== Sub ToggleApplicationCalculation() With Application.CommandBars.ActionControl If .State = msoButtonUp Then .State = msoButtonDown Else .State = msoButtonUp End If End With On Error GoTo ErrorHandler If Application.Calculation = xlManual Then Application.Calculation = xlAutomatic MsgBox "Calculation toggled to Automatic." Else Application.Calculation = xlManual Application.CalculateBeforeSave = True MsgBox "Calculation toggled to Manual." End If ErrorHandler: End Sub 'ToggleApplicationCalculation Private Sub Workbook_BeforeClose(Cancel As Boolean) On Error Resume Next Application.CommandBars("Standard").Controls( _ "ToggleApplicationCalculation").Delete On Error GoTo 0 End Sub '<<=============================== '=============================== Private Sub Workbook_BeforeClose(Cancel As Boolean) On Error Resume Next Application.CommandBars("Standard").Controls( _ "ToggleApplicationCalculation").Delete On Error GoTo 0 End Sub '<<=============================== =============================== Private Sub Workbook_Open() On Error Resume Next Application.CommandBars("Standard").Controls( _ "ToggleApplicationCalculation").Delete On Error GoTo 0 With Application.CommandBars("Standard") With .Controls.Add(Temporary:=True) .BeginGroup = True .Style = msoButtonIcon .FaceId = 283 .Caption = "CalculateToggle" .State = msoButtonUp .OnAction = "ToggleApplicationCalculation" End With End With End Sub '<<=============================== --- Regards, Norman "Mike" wrote in message ... Thanks for all help. I was able to get the Toggle Calc .xla add-in working with the following code. However, I can't figure out how to change this macro to be "depressed" when Calc is ON, and "pushed up" when the Calc is OFF. Any help? I cannot get msoButtonUp, msoButtonDown, and .State to work at all. Thanks! **** IN THE MODULE'S VBA **** Sub ToggleApplicationCalculation() On Error GoTo ErrorHandler If Application.Calculation = xlManual Then Application.Calculation = xlAutomatic MsgBox "Calculation toggled to Automatic." Else Application.Calculation = xlManual Application.CalculateBeforeSave = True MsgBox "Calculation toggled to Manual." End If ErrorHandler: End Sub 'ToggleApplicationCalculation **** IN THISWORKBOOK'S VBA **** Private Sub Workbook_BeforeClose(Cancel As Boolean) On Error Resume Next Application.CommandBars("Standard").Controls( _ "ToggleApplicationCalculation").Delete On Error GoTo 0 End Sub Private Sub Workbook_Open() On Error Resume Next Application.CommandBars("Standard").Controls( _ "ToggleApplicationCalculation").Delete On Error GoTo 0 With Application.CommandBars("Standard") With .Controls.Add(Temporary:=True) .BeginGroup = True .Style = msoButtonIcon .FaceId = 283 .Caption = "CalculateToggle" .OnAction = "ToggleApplicationCalculation" End With End With End Sub |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
where is tthe "read only" TOGGLE button ? | Excel Worksheet Functions | |||
Excel - Golf - how to display "-2" as "2 Under" or "4"as "+4" or "4 Over" in a calculation cell | Excel Discussion (Misc queries) | |||
My calc key on Excel changes box to "Text" Box and doesn't calc ? | Charts and Charting in Excel | |||
"Toggle total row" button not enabled in Excel 2003 | Excel Discussion (Misc queries) | |||
Working out age from "Day" "Month" "Year" | Excel Worksheet Functions |