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

x
?
Solved

Excel VB.net Add-in Right click menu issue

Posted on 2013-01-12
2
Medium Priority
?
600 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: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
2 Comments
 
LVL 23

Accepted Solution

by:
Michael Fowler earned 2000 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:Murray Brown
ID: 38773627
Thanks
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

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…
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

705 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