View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
GS[_2_] GS[_2_] is offline
external usenet poster
 
Posts: 3,514
Default Can't get Control.State to work

After serious thinking wal wrote :
Excel 2003

I created a button using Right-click-on-control-bars Customize, and
assigned the following macro to it:

Sub ToggleCalculation()

Dim myBar As CommandBar, myControl As CommandBarButton
Set myBar = CommandBars("myMacros")
Set myControl = myBar.Controls("ToggleCalculation")

If Application.Calculation = xlCalculationAutomatic Then
Application.Calculation = xlCalculationManual
myControl.State = msoButtonUp
ElseIf Application.Calculation = xlCalculationManual Then
Application.Calculation = xlCalculationAutomatic
myControl.State = msoButtonDown
End If

MsgBox myControl.State
End Sub

When I press the button, the calculation setting does toggle. But the
button stays in the "up" position (.State = 0).

Any ideas? Thanks.


Why are you playing around with the button state? I suspect you're
trying to hint whether calculation is on or the other. It would be
easier to change the caption so there's no ambiguity which mode
calculation is in without messing around with the button state.
Besides, how do you expect to restore calc mode when the button is down
(and so can't be clicked)?

Try this...

Sub ToggleCalculation()
Select Case Application.Calculation
Case xlCalculationAutomatic
Application.Calculation = xlCalculationManual
CommandBars.ActionControl.Caption = "Set Automatic Calculation"
Case xlCalculationManual
Application.Calculation = xlCalculationAutomatic
CommandBars.ActionControl.Caption = "Set Manual Calculation"
End Select
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc