+ Reply to Thread
Results 1 to 14 of 14

Add-In & Cell Context (Right-Click) Menu

Hybrid View

EnigmaMatter Add-In & Cell Context... 02-27-2014, 12:35 PM
Izandol Re: Add-In & Cell Context... 02-27-2014, 12:54 PM
EnigmaMatter Re: Add-In & Cell Context... 02-27-2014, 01:10 PM
Izandol Re: Add-In & Cell Context... 02-27-2014, 01:14 PM
EnigmaMatter Re: Add-In & Cell Context... 02-27-2014, 01:16 PM
EnigmaMatter Re: Add-In & Cell Context... 02-27-2014, 05:09 PM
Izandol Re: Add-In & Cell Context... 02-27-2014, 06:05 PM
EnigmaMatter Re: Add-In & Cell Context... 02-27-2014, 06:39 PM
Izandol Re: Add-In & Cell Context... 02-27-2014, 06:43 PM
EnigmaMatter How do I add to all three? 02-27-2014, 07:37 PM
EnigmaMatter By the way, I keep trying to... 02-27-2014, 07:38 PM
Izandol Re: Add-In & Cell Context... 02-27-2014, 08:36 PM
EnigmaMatter Thanks! I hope to contribute... 02-27-2014, 09:29 PM
Izandol Re: Add-In & Cell Context... 02-28-2014, 04:39 AM
  1. #1
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Add-In & Cell Context (Right-Click) Menu

    Hello,

    I have created an Add-In.

    How do I add "Execute Macro" (that executes the Macro) to the Cell Context Menu in an Add-In.

    To clarify, when users load my Add-In, I would like for them to be able to right-click and access my "Execute Macro" choice similar to how one would select "Copy" or "Cut".

    Thank You,

    Tyler B. Berger

  2. #2
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Add-In & Cell Context (Right-Click) Menu

    You may use:
    Sub addButton()
        Dim cbr As CommandBar
    Dim ctl As CommandBarControl
        Set cbr = Application.CommandBars("Cell")
        Set ctl = cbr.Controls.Add(msoControlButton, , , , True)
        With ctl
          .Caption = "Execute macro"
          .OnAction = "'" & ThisWorkbook.Name & "'!Macro_name"
          .Style = msoButtonCaption
       End With
    End Sub
    You may call this code from Workbook_Open event of your add-in.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  3. #3
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: Add-In & Cell Context (Right-Click) Menu

    I have:

    Sub AddToShortCut()
        Dim Bar As CommandBar
    Dim NewControl As CommandBarButton
        DeleteFromShortcut
        Set Bar = Application.CommandBars("Cell")
        Set NewControl = Bar.Controls.Add _
            (Type:=msoControlButton, ID:=1, _
             temporary:=True)
        With NewControl
            .Caption = "&Send Incoming Inventory to Business Operations"
            .OnAction = "CreateListofIncomingInventory2"
            .Style = msoButtonIconAndCaption
        End With
    End Sub
    
    Sub DeleteFromShortcut()
        On Error Resume Next
        Application.CommandBars("Cell").Controls _
          ("&Send Incoming Inventory to Business Operations").Delete
    End Sub
    AddToShortcut is called on Workbook Open and DeleteFromShortcut is called on Workbook Close. Works great in an .XLSM. Does not work when I convert to Add-In.

  4. #4
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Add-In & Cell Context (Right-Click) Menu

    May you zip and post add-in please? Do you have errors or simply no new control?

  5. #5
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: Add-In & Cell Context (Right-Click) Menu

    Izandol,

    Too much personal information in Workbook.

    No error, simply no new control.

  6. #6
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: Add-In & Cell Context (Right-Click) Menu

    Thanks for your help Izandol!

  7. #7
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Add-In & Cell Context (Right-Click) Menu

    It is fixed?

  8. #8
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366

    Re: Add-In & Cell Context (Right-Click) Menu

    It seems to be an issue local to my machine, sometimes it works, sometimes it doesn't.

  9. #9
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Add-In & Cell Context (Right-Click) Menu

    It is perhaps issue with worksheet view. Excel has two Cell context menus - one for Normal view and Page Layout and one for Page break preview.
    Last edited by Izandol; 02-28-2014 at 04:37 AM.

  10. #10
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366
    How do I add to all three?
    Thank You,

    EnigmaMatter

  11. #11
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366
    By the way, I keep trying to give you Rep, but it won't let me yet.

  12. #12
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Add-In & Cell Context (Right-Click) Menu

    Do not worry about rep - I wish only to repay some of what I have gained from this forum!

    Best way is to loop through commandbars collection until you find first Cell menu, add control, then add same control to commandbar with index 3 higher. You may also simply loop with counter until you have found 2 Cell menus. I think if you use CustomUI in 2010 it is easier.

  13. #13
    Forum Contributor
    Join Date
    02-04-2014
    Location
    Florida, United States
    MS-Off Ver
    Excel 2010, Excel 2013
    Posts
    366
    Thanks! I hope to contribute one day too.

    So the other cell context menus have indexes of 2 and 3?

  14. #14
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Add-In & Cell Context (Right-Click) Menu

    There are only two - one has an index 3 more than the other. For example:
    Sub bar()
        Dim cbr                        As CommandBar
    
        For Each cbr In Application.CommandBars
            Debug.Print cbr.Name
            If LCase$(cbr.Name) = "cell" Then
                With cbr.Controls.Add(msoControlButton)
                    .Caption = "foo"
                    .OnAction = "foobar"
                    .Style = msoButtonCaption
                    .Enabled = True
                    .Visible = True
                End With
                With Application.CommandBars(cbr.Index + 3).Controls.Add(msoControlButton)
                    .Caption = "foo"
                    .OnAction = "foobar"
                    .Style = msoButtonCaption
                    .Enabled = True
                    .Visible = True
                End With
                Exit For
    
            End If
        Next cbr
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Screwed Up my Right Click Context Menu, Please Help
    By cpmame in forum Excel General
    Replies: 3
    Last Post: 03-12-2009, 12:13 PM
  2. [SOLVED] access [contextual||context||right-click] [menu||commandbar] of ch
    By mrmack in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-21-2006, 04:35 AM
  3. [SOLVED] Context menu of Cell
    By MadDog in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-04-2006, 06:35 AM
  4. Right-Click (Context Menu)
    By Kryptonix in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-25-2005, 11:05 AM
  5. Right Click Context Menu
    By Guy Lapierre in forum Excel General
    Replies: 1
    Last Post: 03-30-2005, 07:06 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1