PDA

View Full Version : Solved: Adding a button to a commandbar (Excel '97)



phendrena
05-06-2009, 03:59 AM
Hi,

I'm trying to add the macro "ProtectAll" to my custom commandbar using the following code :

Sub AddButton()
With CommandBars("Personal Toolbar").Controls.Add(Type:=msoControlButton)
.FaceId = 2
.OnAction "ProtectAll"
.Caption "Protect ALL worksheets"
End With
End Sub

The code errors with a compile error 'Invalid Use Of Property' and then highlights the .OnAction line if i comment this out it also fails and highlights .Caption line.

Please help! :help

Thanks,

Bob Phillips
05-06-2009, 04:07 AM
With CommandBars("Personal Toolbar").Controls.Add(Type:=msoControlButton)
.FaceId = 2
.OnAction = "ProtectAll"
.Caption = "Protect ALL worksheets"
End With

phendrena
05-06-2009, 04:16 AM
OMG! :wot

D'OH! :doh:

I can't believe I missed the '='.
I've been staring at the code for the last hour scratching my head. It would be something stupidly obvious!

Thanks xld :beerchug: