Consulting

Results 1 to 3 of 3

Thread: Right-Click on Toolbar button

  1. #1
    VBAX Regular
    Joined
    Feb 2009
    Posts
    55
    Location

    Right-Click on Toolbar button

    Hello

    I create my toolbar using the code below

    [vba]
    MacNames(0) = "MoveSelectedUp"
    TipText(0) = MacNames(0) + " vbcrlf vbcrlf Move Up Selected rows"
    iconnum(0) = 38
    MacNames(1) = "MoveSelectedDown"
    TipText(1) = MacNames(1) + " vbcrlf vbcrlf Move Down Selected rows "
    iconnum(1) = 40
    MacNames(2) = "CloneSelected"
    TipText(2) = MacNames(2) + " vbcrlf vbcrlf Clone Selected rows"
    iconnum(2) = 29
    [/vba]

    [vba]
    For iCtr = LBound(MacNames) To UBound(MacNames)
    tt = TipText(iCtr)
    tt = Replace(tt, "vbcrlf", vbCrLf)
    With .Controls.add(Type:=msoControlButton)
    .OnAction = "'" & ThisWorkbook.Name & "'!" & MacNames(iCtr)
    .Style = msoButtonIconAndCaption
    .FaceId = iconnum(iCtr)
    .TooltipText = tt
    End With
    Next iCtr
    [/vba]

    My Questions are:
    1 - When I click on a toolbar button - the assigned macro is invoked. Can I invoke a different macro when I right-click on a toolbar button ?

    2 - Is there a way to create a menu that will be displayed when I right-click on a toolbar button ? Currently, when I right click any of my toolbar buttons, I get the menu of "Standard Fornmatting..." which is actually as if I clicked on "View >> Toolbars"



    Thanks for any help
    Last edited by Bob Phillips; 05-02-2011 at 01:52 AM. Reason: Changed Quote tags to VBA tags

  2. #2
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    Instead of adding a command button to the control bar, you could add a dropdown menu of routines to be selected.

    This code takes an existing command bar ("Custom 1") and adds a menu with two sub items to be selected.

    [VBA]Sub test()
    With Application.CommandBars("Custom 1")

    Rem add menu type control to CommandBar
    With .Controls.Add(Type:=msoControlPopup, temporary:=True)
    .Caption = "New Menu"

    Rem add first menu item
    With .Controls.Add(Type:=msoControlButton, temporary:=True)
    .Caption = "First Routine"
    .FaceId = 162
    .OnAction = "Macro1"
    End With

    Rem add second menu item
    With .Controls.Add(Type:=msoControlButton, temporary:=True)
    .Caption = "Second Routine"
    .OnAction = "Macro2"
    End With

    End With
    End With
    End Sub

    Sub Macro1()
    MsgBox "1"
    End Sub
    Sub macro2()
    MsgBox "2"
    End Sub[/VBA]

  3. #3
    VBAX Regular
    Joined
    Feb 2009
    Posts
    55
    Location
    This is real nice !

    but

    it opens the menu when I click on the button....

    I am looking to run a macro on click and open the menu on right-click

    any idea ???

    many thanks

Posting Permissions

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