Consulting

Results 1 to 8 of 8

Thread: How Do I Get Commandbar Values?

  1. #1

    Exclamation How Do I Get Commandbar Values?

    I am creating a custom toolbar and want to add some of the default excel commandbarbuttons. I have added the "Font Colour" toolbar button. This button is a msoControlSplitButtonPopup type.

    The question is, if I attach a macro to this button, how do I determine which value (or colour) was selected?

    I would like to do something similar with the "Line Style" and "Line Colour" toolbar buttons.

  2. #2
    VBAX Master TonyJollans's Avatar
    Joined
    May 2004
    Location
    Norfolk, England
    Posts
    2,291
    Location
    If you attach a macro to the button, then surely the built-in action won't run so there won't be any selection to be made.
    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

  3. #3
    You cannot attach a macro to that type of control.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  4. #4
    Perhaps there is a workaround solution. Is it possible to retrieve the current value/selection from a font button, or fill button. ie how can I retrieve the current colour selection showing on the face of the button?

  5. #5
    Well, you cannot access the button's face easily, but the tooltip does give what color is selected:

    MsgBox Application.CommandBars("formatting").FindControl(ID:=401).TooltipText

    But that gives you no clue what color index that is in the workbook...
    How about telling us what you want to achieve exactly?
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  6. #6
    I am developing a toolbar for formatting broders, and want to use the "Line style" toolbar drop-down as a method of changing all the borders of a selection to that line style. I would also like to use the "line colour" toolbar button to do the same thing. I can then use those two excel menus in the toolbar and then have an "apply" button to read the selections and apply the appropriate style to the cell selection. This would be much nicer than having an ugly custom menu.

  7. #7
    Moderator VBAX Master geekgirlau's Avatar
    Joined
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,464
    Location
    Why don't you just add the default button for those options to your toolbar?

    [vba]
    ' add buttons
    With Application.CommandBars("mnuTest").Controls
    .Add Type:=msoControlSplitButtonPopup, ID:=401, Before:=1
    .Add Type:=msoControlButtonPopup, ID:=692, Before:=2
    .Add Type:=msoControlSplitButtonPopup, ID:=1692, Before:=3
    End With
    [/vba]

  8. #8
    I think I might just give up on this one. Adding the default options is fine, but I might as well just copy the original control.

    What I want is to read the type of line showing on the commandbarbutton, or read the currently selected colour on the commandbarbutton.

Posting Permissions

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