Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VSTO Right Click on Sheet menu

Posted on 2013-01-07
7
Medium Priority
?
1,247 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:Murray Brown
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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:Murray Brown
ID: 38754235
I am trying to build my own
0
 

Author Comment

by:Murray Brown
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 2000 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:Murray Brown
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

715 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