PDA

View Full Version : How to add to new button of the list of values?



akokin
09-18-2008, 11:29 PM
Hello.
I creating one toolbar and creating on it one button by next macros (below).
I wish to add to my new button the list of some values (e.g. the list of bookmarks). If I will use the type of button as "msoControlPopup" then it will possible but such button don't will has picture. However if I will use the type of button as "msoControlButton", then how can I add to this button of list?
Thank you very much.
My codes:
Create new toolbar
Sub setCB()
Set cB = CommandBars.Add( _
Name:="My bar", _
Position:=msoBarLeft, _
menubar:=False, _
temporary:=False)
CommandBars("My bar").Enabled = True
CommandBars("My barl").Visible = True
Set cB = Nothing
End Sub

Create new button on my toolbar
Sub addCBB()
Set cbb = cB.Controls.Add(msoControlButton)
With cbb
.TooltipText = "My list of values"
.Tag = "rfButton"
.FaceId = 371
End With
Set cbb = Nothing
End Sub

fumei
09-19-2008, 10:54 AM
I do not understand the question. A button is a button, not a list.

akokin
09-19-2008, 10:40 PM
Is wonder there is a way to make button with list? Maybe not button and some other? Like it (from add-in WordToys):

http://clip2net.com/clip/m8665/1221889157-clip-42kb.jpg

fumei
09-22-2008, 11:44 AM
That is not a button with list.

akokin
09-22-2008, 09:02 PM
Ok, but what it is? And how it can simulate by VBA?
Thank you very much.

fumei
09-24-2008, 08:22 AM
As far as I can tell - and I do not have, nor do I think I would use, WordsToys - it is a button that displays another menu. In other words, it is a menu, not a commandbutton.

Please try and describe precisely what you are trying to do.

akokin
09-24-2008, 08:37 AM
Strictly speaking I try to make such button which displays menu. The menu - it is can be the list of recent files or the list of bookmarks or others. I created it with by the pop-up menu but I think that it can make otherwise right by with the regular menu.

fumei
09-25-2008, 12:08 PM
WHY are you trying to do this???

Buttons are essentially command objects. Clicking a button does something. technically, yes, you could make that something a change of display....but WHY?

It seems to me that you are talking about menus...not buttons. Take a look at the attached document.

There is a New Menu on the top toolbar. Clicked, it displays menu items, and these menu items can display further fly out menu items. Those menu items action procedures.

It also has a another different menu (Current Bookmarks), that when clicked displays a list of actions. These are the names of the current bookmarks, and the action is to display a messagebox with the bookmark contents, and then move the selection to that specific bookmark.

I have no idea if this is anything like what you are trying to describe you want. I still do not really understand what you want. However, a button usually performs an action.

akokin
09-26-2008, 05:05 AM
Hello.
Thank you very much for this example. I did it early. But I want to get not item menu on the tool bar. It's simple. I wanted to know is it possible to create menu (like on that screenshot) for button (by clicking on it).
Why? Why not? I see 3 reasons:
1. User's toolbar maybe full and there is no free space for my new buttons (items menu).
2. Position on left side is very favourable for new toolbar and button (for macros).
3. I'm very curious and I want to know how it was made in that program "WordToys".
Thank you for your advices and help.

I did it so (with pop-up). But it don't similarly on action from "WordToys":

http://clip2net.com/clip/m0/1222430982-clip-18kb.png
(http://clip2net.com/clip/m0/1222430982-clip-18kb.png?nocache=1)

TonyJollans
09-26-2008, 12:26 PM
Hi Anton,

WordToys has some clever code behind the scenes. The Toolbar buttons execute code in a dll that builds something that looks something like a popup menu - but isn't. My guess is that they are not Word objcts at all, more likely Windows ones - but it is just a guess; it certainly isn't possible natively in Word, to do what WordToys does.

It doesn't look as though WordToys is supported any more as the web page has gone.

fumei
09-26-2008, 03:27 PM
And it has (had?) some very bad reviews.

akokin
09-26-2008, 09:10 PM
Hi Tony. Yes, I thank you very much. I wanted to say about this .dll-file but I thought it had some commands on VBA. It's grievous. But I will think how to do it though. Maybe in VB.
Thank you very much for your helpful advices and answers.
Regards, Anton Kokin

TonyJollans
09-27-2008, 03:52 PM
Hi Anton,

I decided to have a play with this and it isn't very difficult to do.

Create two macros:

Sub ButtonClick()

Dim CB As CommandBar
Dim ndx As Long

Set CB = CommandBars.Add("ButtonPopup", msoBarPopup)

For ndx = 1 To Application.RecentFiles.Count
With CB.Controls.Add(msoControlButton)
.OnAction = "PopupActionMacro"
.Caption = Application.RecentFiles(ndx).Name
End With
Next

With CommandBars.ActionControl
CB.ShowPopup .Left, .Top + .Height - 2
End With

CB.Delete

End Sub

Sub PopupActionMacro()
MsgBox "Recent File " & CommandBars.ActionControl.Caption & " chosen."
End Sub

Then, with the standard Toolbar Customize UI, add a control button somewhere for the macro ButtonClick.

Click it!

akokin
09-27-2008, 09:40 PM
Hi Tony. Yes! It is very nice! Thank you very much!
Regards, sincerely and shower praises,
Anton Kokin

akokin
09-29-2008, 08:16 PM
Hi Tony.
I assigned for this button of tooltip:

With CommandBars.ActionControl
.TooltipText = "List of recent files"
cb.ShowPopup .Left + 25, .Top + .Height - 24
End With

But I can't assign for it the icon (property "FaceId"). Is it possible?
Thank you for help.
Regards, Anton.

TonyJollans
09-30-2008, 01:33 AM
It works for me - what error do you get?

akokin
09-30-2008, 02:49 AM
Hi Tony.
No, I not give the errors, but I not have mthod to add this property (FaceId) for my button.

http://wordexpert.ru/wp-content/uploads/iconButton.gif

I was modernized your macro. Please see below:
Dim cb As CommandBar
Dim mBtn As CommandBarButton
Dim dirRF As CommandBarButton
Dim clearRF As CommandBarButton
Dim bb As CommandBarButton
Dim i As Long
Dim rf As RecentFile

Sub buttonMenu()
On Error Resume Next
Set cb = CommandBars.Add("btnPopup", msoBarPopup)
For Each rf In Application.RecentFiles
If Len(Dir(rf.Path & "\" & rf.Name)) = 0 Then
Application.RecentFiles(rf.Index).Delete
End If
Next rf
For i = 1 To Application.RecentFiles.Count
Set mBtn = cb.Controls.Add(msoControlButton)
With mBtn
.Caption = Application.RecentFiles(i)
.Tag = Application.RecentFiles(i).Path & "\" & Application.RecentFiles(i).Name
.OnAction = "openRF"
End With
Next i
Set dirRF = cb.Controls.Add(msoControlButton)
With dirRF
.Caption = "More docs..."
.BeginGroup = True
'.OnAction = "openDlgRF"
.FaceId = 1661
End With
Set clearRF = cb.Controls.Add(msoControlButton)
With clearRF
.Caption = "Clear list"
.BeginGroup = True
'.OnAction = "clearMRU"
.FaceId = 1088
End With
With CommandBars.ActionControl
' .TooltipText = "List of recent files"
cb.ShowPopup .Left + 25, .Top + .Height - 24
End With
Set cb = Nothing
Set mBtn = Nothing
Set dirRF = Nothing
Set clearRF = Nothing
End Sub

Sub openRF()
Documents.Open CommandBars.ActionControl.Tag
End Sub

TonyJollans
09-30-2008, 06:14 AM
Hi Anton,

I don't have any trouble changing the icon - either manually or with .FaceId in code - and as you don't have a default icon there you must have changed it yourself already. What exactly is it that you can't do?

akokin
09-30-2008, 06:39 AM
Hi Tony.
I can to cange the icon for this button by manually. But how to do it with .FaceId? Where I should to insert this proprty? I tried to insert it to line:
With CommandBars.ActionControl
' .TooltipText = "List of recent files"
cb.ShowPopup .Left + 25, .Top + .Height - 24
End With
But it not have this property.
Please give me your tips for this.
:banghead:

TonyJollans
09-30-2008, 12:16 PM
I can add it in that code:

With CommandBars.ActionControl
' .TooltipText = "List of recent files"
.FaceId = 47 ' or whatever
cb.ShowPopup .Left + 25, .Top + .Height - 24
End With

but do you particularly want to change it when you display the dropdown?

akokin
09-30-2008, 10:51 PM
Hi Tony.
I not have this property "FaceId". Please see screen:

http://img.photobucket.com/albums/v190/baston/faceid_nothing.gif

I want to change the icon for button, not dropdown list.

But it is work! Very strangely... :dunno
Thank you very much! :hi:

TonyJollans
09-30-2008, 11:55 PM
Ah. now I understand your problem.

ActionControl is a generic 'CommandBarControl' wrapper that does not, itself, havea FaceId property, so the Intellisense does not show it. When the actual control is a CommandBarButton it does have the property and it does work.