Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 22

Thread: How to add to new button of the list of values?

  1. #1
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location

    How to add to new button of the list of values?

    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
    [VBA]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[/VBA]

    Create new button on my toolbar
    [VBA]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[/VBA]

  2. #2
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    I do not understand the question. A button is a button, not a list.

  3. #3
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    Is wonder there is a way to make button with list? Maybe not button and some other? Like it (from add-in WordToys):


  4. #4
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    That is not a button with list.

  5. #5
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    Ok, but what it is? And how it can simulate by VBA?
    Thank you very much.

  6. #6
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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.

  7. #7
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    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.

  8. #8
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    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.

  9. #9
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    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":



  10. #10
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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.
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  11. #11
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    And it has (had?) some very bad reviews.

  12. #12
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    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

  13. #13
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    Hi Anton,

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

    Create two macros:

    [VBA]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[/VBA]

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

    Click it!
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  14. #14
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    Hi Tony. Yes! It is very nice! Thank you very much!
    Regards, sincerely and shower praises,
    Anton Kokin

  15. #15
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    Hi Tony.
    I assigned for this button of tooltip:

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

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

  16. #16
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    It works for me - what error do you get?
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  17. #17
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    Hi Tony.
    No, I not give the errors, but I not have mthod to add this property (FaceId) for my button.



    I was modernized your macro. Please see below:
    [vba]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[/vba]

  18. #18
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    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?
    Enjoy,
    Tony

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

  19. #19
    VBAX Regular
    Joined
    Aug 2007
    Posts
    66
    Location
    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:
    [vba]With CommandBars.ActionControl
    ' .TooltipText = "List of recent files"
    cb.ShowPopup .Left + 25, .Top + .Height - 24
    End With [/vba]
    But it not have this property.
    Please give me your tips for this.

  20. #20
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    I can add it in that code:

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

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

    ---------------------------------------------------------------
    Give a man a fish and he'll eat for a day.
    Teach him how to fish and he'll sit in a boat and drink beer all day.

    I'm (slowly) building my own site: www.WordArticles.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •