LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #12   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Can't get Control.State to work

Peter T brought next idea :
Should work, the "State" should remain as set, try this

Sub delBar()
' run this after testing to clean up
On Error Resume Next
CommandBars("testBar").Delete
End Sub

Sub addBar()
Dim cbr As CommandBar, cbt As CommandBarButton
delBar
Set cbr = CommandBars.Add("testBar", , , True)
cbr.Visible = True
Set cbt = cbr.Controls.Add(1)
With cbt
.Caption = "My Macro"
.OnAction = "MyMacro"
.Style = msoButtonCaption
End With
End Sub

Sub myMacro()
Dim cbt As CommandBarButton
Static b As Boolean
b = Not b
Set cbt = CommandBars.ActionControl
cbt.Caption = "My Macro " & b
cbt.State = b
End Sub

The way State is indicated differs, might be change in colour or a tick to
the left.

(This is not useful for 2007/2010 users unless used on a popup bar)

Regards,
Peter T


"wal" wrote in message
...
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.


I suspect the OP is using a custom toolbar created via the 'Customize'
dialog. If so then setting 'State' has no effect, though no error is
generated by attempting to set this property.

Attempting to do same with any of the built-in commandbars generates an
'automation' error.

--
Garry

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


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
replace state names with state code abbreviations se7098 Excel Worksheet Functions 3 July 25th 09 06:41 PM
How can I show state-by-state data (as silos) on a map of NA Rob Charts and Charting in Excel 0 November 5th 07 03:41 PM
Converting State Names to State Abbreviations aznate Excel Discussion (Misc queries) 1 October 20th 06 06:52 AM
Error Control no work :( CodeSponge[_2_] Excel Programming 5 January 12th 05 09:47 PM


All times are GMT +1. The time now is 08:56 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"