Solved

VSTO Right Click on Sheet menu

Posted on 2013-01-07
7
1,161 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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article will guide you to convert a grid from a picture into Excel format using Microsoft OneNote and no other 3rd party application.
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

861 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