How to create builtIn menu for button on toolbar?

A

avkokin

Hello.
There is the my own toolbar which has one button (which has empty
macro code). The toolbar is on left position. I want to add to my
button builtIn menu which will contains some list of values (e.g. list
of bookmarks and other commands). How I can do it?
Thank you very much.
 
C

Cindy M.

Hi Avkokin,
There is the my own toolbar which has one button (which has empty
macro code). The toolbar is on left position. I want to add to my
button builtIn menu which will contains some list of values (e.g. list
of bookmarks and other commands). How I can do it?
The question is not clear.

Are you looking for the CommandBar.Controls.Add method?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
C

Cindy M.

Hi Avkokin,
No, I want to create the button with own menu like as menu bar. Is
possible it or not?
Yes, you use a popup type of control. But from an earlier message of
yours I assume you already know that? That is the only possibility.
The only other thing is a combobox.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17
2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow
question or reply in the newsgroup and not by e-mail :)
 
A

avkokin

Hi, Cindy.

Thank you very much for your answers. I think that it was did with VB
not VBA.
 
C

Cindy M.

Hi Avkokin,
I think that it was did with VB
not VBA.
If we're talking about a toolbar for Word, then it
basically doesn't matter whether VB or VBA because the
buttons that are available come from the Office CommandBars
object model.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 
A

avkokin

Cindy, I'm sorry for my poor English but I try to explain my own
desires.
I want to create button in left position (on my own toolbar). By
clicking on this button should to opens menu with the list some
values, e.g. the list names of the recent files. If I will use simply
button (as msoControlButton) then I can't use of menu for it or add my
list. If I will use the button type of msoControlPopup then I think
that I can add to it my list. But such button will has view as text
(caption) but not as button with icon. That is the question and that
is the dilemma! I want to create my button (with icon and without
caption) for creating to it my list (my menu). How can I do it?
Thank you very much. Your help is much appreciated.
 
C

Cindy M.

Hi Avkokin,
I want to create button in left position (on my own toolbar). By
clicking on this button should to opens menu with the list some
values, e.g. the list names of the recent files. If I will use simply
button (as msoControlButton) then I can't use of menu for it or add my
list. If I will use the button type of msoControlPopup then I think
that I can add to it my list. But such button will has view as text
(caption) but not as button with icon. That is the question and that
is the dilemma! I want to create my button (with icon and without
caption) for creating to it my list (my menu). How can I do it?
Yes, this was your question in an earlier message which I did answer.

It is not possible.

Best you can do would be to place a regular button next to the popup
button. Do not attach any code to the button. Have the style set to
icon-only. If the user can't click on this button, he'll proably try the
button next to it.

Or use a combobox type of button to list your options.

In the Office object model that's all you can do. There is no "trick" to
work around it.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question
or reply in the newsgroup and not by e-mail :)
 
A

avkokin

Dear Cindy. Thank you very much. What if I will use the contextual
menu? But I unknow how to add caption for this menu. For example:
Sub createList()
'
Dim cbP As CommandBar
Dim mButton As CommandBarButton

Set cbP = CommandBars.FindControl(msoBarPopup)
If Not cbP Is Nothing Then
cbP.Delete
End If

Set cbP = CommandBars.Add("MRU", msoBarPopup)
With cbP
Set mButton = .Controls.Add(msoControlButton)
With mButton
.Caption = "First file"
.Style = msoControlButton
.OnAction = "OpenDoc" 'open recent file
End With
End With

cbP.ShowPopup
Set cbP = Nothing
Set mButton = Nothing

End Sub
 
C

Cindy M.

Hi Avkokin,
What if I will use the contextual
menu? But I unknow how to add caption for this menu.
A contextual menu is what you get if your right-click
something in the text. In order to use a contextual menu
you must either alter an existing right-click menu or you
must trap the Window_BeforeRightClick event to substitute
your menu for the default right-click menu.

Showing a caption is a matter of setting the .STYLE
property to the correct value, using the Enum
msoButtonStyle. That would be msoButtonCaption.

In your sample code you use msoControlButton which is the
wrong Enum. VBA is taking the LONG value of that enum and
applying it to the correct msoButtonStyle enum. That value
is 1, which equals msoButtonIcon.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update
Jun 17 2005)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any
follow question or reply in the newsgroup and not by e-mail
:)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top