Hello
I can toggle the displayed faceID on a custom commandbar with the following
code:

With Application.CommandBars.FindControl(Tag:="Show my folder")
If .FaceId = 1088 Then
.FaceId = 1087
Else
.FaceId = 1088
End If
MsgBox .FaceId, , .Caption

End With

But withmy custom menu the new icon is not displayed, even tho the msgbox
shows that the faceID has been changed. I've tried a new custom menu and a
popup menu on the tools menu with the same result. I've tried Word 2002 and
2007 where it shows under the Add-ins.

I added my menu it like this:
Set myMenu = Application.CommandBars("Menu
Bar").Controls("Tools").Controls.Add(Type:=msoControlPopup)
with myMenu .... ' to add caption, tag etc..

I've tried setting commandbar("Tools").Protection = 0

Help please! What am I missing here?
Word 2002 and 2007

RE: I can toggle faceID on commandbar but not custom menu by MikeB77

MikeB77
Fri Nov 02 04:05:00 PDT 2007

Actually I'm correcting my own post above.
With the custom commandbar I can change the faceID displayed of the buttons
on the top level of the commandbar, but not those on popup menus on the
commandbar, even tho I can change the recorded value of the faceID for all
buttons.

Any ideas on how to make the change display?

Thanks



RE: I can toggle faceID on commandbar but not custom menu by lf

lf
Fri Nov 02 07:17:03 PDT 2007

You need to set the .Style property of the control to a type that allows an
icon. For some reason, this does not seem to be covered very well in the VBA
help.

The code below adds a control to the end of the File menu, sets the caption
to "Test", sets the style to msoButtonIconAndCaption and adds the icon
identified by FaceId 1087:

Dim oControl As CommandBarControl
Set oControl =
CommandBars.ActiveMenuBar.Controls("File").Controls.Add(Type:=msoControlButton)
With oControl
.Caption = "Test"
.Style = msoButtonIconAndCaption
.FaceId = 1087
End With
Set oControl = Nothing

MsoButtonIconAndCaption is a member of msoButtonStyle. You can look up the
members in the Object Browser (F2).

--
Regards
Lene Fredborg
DocTools - Denmark
www.thedoctools.com
Document automation - add-ins, macros and templates for Microsoft Word


"MikeB77" wrote:

> Actually I'm correcting my own post above.
> With the custom commandbar I can change the faceID displayed of the buttons
> on the top level of the commandbar, but not those on popup menus on the
> commandbar, even tho I can change the recorded value of the faceID for all
> buttons.
>
> Any ideas on how to make the change display?
>
> Thanks
>
>

RE: I can toggle faceID on commandbar but not custom menu by MikeB77

MikeB77
Sat Nov 03 02:51:03 PDT 2007

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



RE: I can toggle faceID on commandbar but not custom menu by MikeB77

MikeB77
Sat Nov 03 03:29:00 PDT 2007

Still answering my own posts on this..,
it appears the problem is how I reference the control:

This DOESN'T change the displayed faceID, even tho the faceID number appears
changed:
With Application.CommandBars.FindControl(Tag:="Button2"))
.faceID = 123
end with

This DOES change the displayed faceID:
With CommandBars("MyBar").Controls("subMenu").Controls("Button2")
.faceID = 123
end with

Problem is I've got a big complex menu (lots of popups) and would have great
trouble tracking all the steps for some controls.

Can someone explain this or suggest a solution, more along the .findcontrols
line?


Thanks!

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
>
>