RE: I can toggle faceID on commandbar but not custom menu by lf
lf
Sat Nov 03 04:39:00 PDT 2007
As far as I can see, the problem has nothing to do with whether you can see
the control or not. If you insert an "End If" after the line:
x = "Button2"
in the procedure "aChangeFace", it works (at least in my test).
You should also set the CustomizationContext whenever you change CommandBars
in order to make sure in which context the changes are made.
--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word
"MikeB77" wrote:
> HI Lene
> Thanks for having a look. yes I've set the button .style
> =MsoButtonIconAndCaption when i created the control, and can see the image
> originally assigned to the control.
> Problem is I can't change the displayed image unless I can actually see it
> (I don't mean .visible). I.e it has to be displayed on a commandbar to
> change. It won't change if on a popup on the same bar, nor a menu bar popup
> etc.
>
> At the risk of being very boring, here's some code that shows the problem.
> it can change the "Button1" image, but not for "Button2":
>
> Sub aChangeFace() 'change the faceID shown
> x = "Button1"
> If MsgBox("button 1 (y) or 2(n)", vbYesNo, "change faceID") = vbNo Then
> x = "Button2"
> With Application.CommandBars.FindControl(Tag:=x)
> waz = .FaceId
> If .FaceId = 1088 Then
> .FaceId = 1087
> Else
> .FaceId = 1088
> End If
> MsgBox "now= " & .FaceId, , .Caption & " faceID was " & waz
> End With
> End Sub
> Sub aMakeMyBar()
> Dim myMenu As CommandBar
> Dim btn As CommandBarButton
> Dim subMenu As CommandBarPopup
>
> On Error Resume Next
> Application.CommandBars("MyBar").Delete
> On Error GoTo 0
>
> Set myMenu = Application.CommandBars.Add("MyBar", msoBarTop, , True)
> myMenu.Visible = True
> With myMenu.Controls
> Set btn = .Add(Type:=msoControlButton)
> With btn
> .Style = msoButtonIconAndCaption
> .FaceId = 123
> .Caption = "Button1"
> .Tag = "Button1"
> .OnAction = "ButtonAction1"
> End With
>
> Set subMenu = .Add(Type:=msoControlPopup)
> With subMenu
> .Caption = "subMenu"
> .Tag = "subMenu"
> Set btn = .Controls.Add(Type:=msoControlButton)
> With btn
> .Style = msoButtonIconAndCaption
> .FaceId = 123
> .Caption = "Button2"
> .Tag = "Button2"
> .OnAction = "ButtonAction2"
> End With
> End With
> End With
> End Sub
> Sub ButtonAction1()
> MsgBox "Button 1 Click."
> End Sub
> Sub ButtonAction2()
> MsgBox "Button 2 Click."
> End Sub
>
>