Solved

VSTO Right Click on Sheet menu

Posted on 2013-01-07
7
1,105 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Introduction While answering a recent question (http:/Q_27311462.html), I created an alternative function to the Excel Concatenate() function that you might find useful.  I tested several solutions and share the results in this article as well as t…
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Viewers will learn the basics of slicers and timelines for both PivotTables and standard Excel tables in Excel 2013.
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.

746 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

8 Experts available now in Live!

Get 1:1 Help Now