Solved

VB.net Excel Add-in

Posted on 2013-01-28
2
421 Views
Last Modified: 2013-01-29
Hi

Through the help of an expert I got a custom right click menu to work in my Excel VB.net add-in. I am ow looking for a way to add a menu item to the bottom of the usual Excel right click menu, instead of overriding as done in the following code....


   Dim cellbar As Office.CommandBar
    WithEvents button As Office.CommandBarButton

    Private Sub Application_SheetBeforeRightClick(ByVal Sh As Object, ByVal Target As Microsoft.Office.Interop.Excel.Range, ByRef Cancel As Boolean) Handles Application.SheetBeforeRightClick
        Try


            Dim oWorkbookName As String = Globals.ThisAddIn.Application.ActiveWorkbook.Name
            If oWorkbookName = "Task Master.xlsx" Or oWorkbookName = "Task Master.xls" _
                                              Or oWorkbookName = "Task Master.xlsm" Then

                oOriginalValue = Target.Value
                oCellAddress = Target.Address

                Cancel = True
                cellbar.ShowPopup()

            Else

                Cancel = False
            End If
        Catch ex As Exception
            MsgBox("Task Master Right Click menu failure (Custom right click menu)." & ex.Message)
        End Try

    End Sub
 

   Private Sub Application_WorkbookActivate(ByVal Wb As Microsoft.Office.Interop.Excel.Workbook) Handles Application.WorkbookActivate
        '**** Initiate custom right click menu ONLY on Workbook activation (and where Workbook is Task Master...)
        Try

            If Wb.Name = "Task Master.xls" Or Wb.Name = "Task Master.xlsx" Or Wb.Name = "Task Master.xlsm" Then
                'NOTE - this menu is a brand new one and overrides the existing Excel right click
                cellbar = Me.Application.CommandBars.Add("Testing2", 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 = "MYRIGHTCLICKMENU2"
                End If
            End If

        Catch ex As Exception
            MsgBox("Task Master Workbook Activation failure (Custom right click menu)." & ex.Message)
        End Try
    End Sub

    Private Sub Application_WorkbookDeactivate(ByVal Wb As Microsoft.Office.Interop.Excel.Workbook) Handles Application.WorkbookDeactivate
        '**** CANCEL custom right click menu ONLY on Workbook activation (and where Workbook is Task Master...)
        Try
            If Wb.Name = "Task Master.xls" Or Wb.Name = "Task Master.xlsx" Or Wb.Name = "Task Master.xlsm" Then
                button = Nothing
            End If
        Catch ex As Exception
            MsgBox("Task Master Workbook Deactivation failure (Custom right click menu)." & ex.Message)
        End Try
    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 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 38826338
0
 

Author Closing Comment

by:Murray Brown
ID: 38831616
Thanks very much
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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!
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

626 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