Solved

VSTO Right Click on Sheet menu

Posted on 2013-01-07
7
1,136 Views
Last Modified: 2013-01-08
Hi

I have tried a few times in the past to build a right click menu in my
VB.net Excel Add-in but have not managed to get a working version going.
Does anyone know of a good artcle on MSDN or the like that walks you through
this. When the user right clicks on a sheet I want the menu to appear
0
Comment
Question by:murbro
  • 4
  • 3
7 Comments
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 38754151
Are you trying to create your own, or use the default Cell (or other shortcut) menu? You'd basically need to build a new commandbar then use its ShowPopup method and cancel the right-click event.
0
 

Author Comment

by:murbro
ID: 38754235
I am trying to build my own
0
 

Author Comment

by:murbro
ID: 38754242
Any chance you have a code example of the method you mentioned? Thanks
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 85

Expert Comment

by:Rory Archibald
ID: 38754305
Not offhand since I don't use .Net but I'll try and put something together later on.
0
 
LVL 85

Accepted Solution

by:
Rory Archibald earned 500 total points
ID: 38754506
This should get you started:

Imports Office = Microsoft.Office.Core
Imports Excel = Microsoft.Office.Interop.Excel
Public Class ThisAddIn
    Dim cellbar As Office.CommandBar
    WithEvents button As Office.CommandBarButton


    Private Sub ThisAddIn_Startup() Handles Me.Startup
        cellbar = Me.Application.CommandBars.Add("Testing", Office.MsoBarPosition.msoBarPopup, False, True)
        If button Is Nothing Then
            ' add the button
            button = DirectCast(cellbar.Controls.Add(Office.MsoControlType.msoControlButton, , , , True), Office.CommandBarButton)
            button.Caption = "Refresh"
            button.BeginGroup = True
            button.Tag = "MYRIGHTCLICKMENU"
        End If
    End Sub

    Private Sub button_Click(Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles button.Click
        MsgBox("Hello")
    End Sub

    Private Sub Application_SheetBeforeRightClick(Sh As Object, Target As Microsoft.Office.Interop.Excel.Range, ByRef Cancel As Boolean) Handles Application.SheetBeforeRightClick
        Cancel = True
        cellbar.ShowPopup()
    End Sub
End Class

Open in new window

0
 

Author Closing Comment

by:murbro
ID: 38754609
Fantasic! Worked perfectly. Thanks very much for taing the time out to solve a problem that no one else could help me with
0
 
LVL 85

Expert Comment

by:Rory Archibald
ID: 38755093
Glad to help! :)

One of my goals for this year is to learn more about Office / .Net development so it's nice to get an early start.

Of course that will come right after I become fluent in DAX/MDX for PowerPivot, so I'm not holding my breath. ;)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Merging-Splitting-Multiple-Rows 33 46
Excel macro runs twice 13 51
excel help 4 20
Excel - Duplicate values in columns 4 16
Approximate matching with VLOOKUP and MATCH seems to me to be a greatly under-used technique, and one which is vital for getting good performance out of large lookups. Until recently I would always have advised using an exact match for simplicity an…
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now