Solved

VB.net Excel Add-in

Posted on 2013-01-28
2
414 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:murbro
2 Comments
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 500 total points
ID: 38826338
0
 

Author Closing Comment

by:murbro
ID: 38831616
Thanks very much
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
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…
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 in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

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

17 Experts available now in Live!

Get 1:1 Help Now