Solved

VSTO Right Click on Sheet menu

Posted on 2013-01-07
7
1,174 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

749 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