Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / November 2007

Tip: Looking for answers? Try searching our database.

I can toggle faceID on commandbar but not custom menu

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MikeB77 - 02 Nov 2007 11:37 GMT
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
MikeB77 - 02 Nov 2007 12:05 GMT
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
Lene Fredborg - 02 Nov 2007 15:17 GMT
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).

Signature

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

> Actually I'm correcting my own post above.
> With the custom commandbar I can change the faceID displayed of the buttons
[quoted text clipped - 5 lines]
>
> Thanks
MikeB77 - 03 Nov 2007 10:51 GMT
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
Lene Fredborg - 03 Nov 2007 12:39 GMT
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.

Signature

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

> HI Lene
> Thanks for having a look.  yes I've set the button .style
[quoted text clipped - 65 lines]
> End Sub
>  
MikeB77 - 03 Nov 2007 11:29 GMT
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!

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.