Solved

Excel VB.net Add-in Right click menu issue

Posted on 2013-01-12
2
592 Views
Last Modified: 2013-01-14
Hi
I have several add-ins running in Excel that I have built. In one of them I use the code
below to get a right click menu. It is used with a specific spreadsheet that has a pivot table
and overrides the usual right click menu.
My problem is that it does this for all spreadsheets. How do I add extra control to let
Excel run its usual right click in other spreadsheets and only run the customized one when
I need it to?


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

        Try
            'NOTE - this menu is a brnd new one and overrides the existing Excel right click
            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 = "Add/Edit Tasks"
                button.BeginGroup = True
                button.Tag = "MYRIGHTCLICKMENU"
            End If

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

        Try

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub
    Private Sub button_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles button.Click
        Call oAddEdit_Tasks()
    End Sub

    Private Sub Application_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Microsoft.Office.Interop.Excel.Range, ByRef Cancel As Boolean) Handles Application.SheetBeforeRightClick
        Cancel = True
        cellbar.ShowPopup()
    End Sub
0
Comment
Question by:murbro
2 Comments
 
LVL 23

Accepted Solution

by:
Michael74 earned 500 total points
ID: 38772999
You could try testing for the workbook/worksheet name in the SheetBeforeRightClick event to determine wether to cancel the default action or not
Michael
0
 

Author Closing Comment

by:murbro
ID: 38773627
Thanks
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

Convert between Excel file formats (.XLS, .XLSX, .XLSM) with/without macro option David Miller (dlmille) Intro Over this past Fall, I've had the opportunity to see several similar requests and have developed a couple related solutions associate…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

937 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

7 Experts available now in Live!

Get 1:1 Help Now