Solved

VB.net Excel Add-in

Posted on 2013-01-28
2
415 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

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

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
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…
The viewer will learn how to simulate a series of sales calls dependent on a single skill level and learn how to simulate a series of sales calls dependent on two skill levels. Simulating Independent Sales Calls: Enter .75 into cell C2 – “skill leve…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

863 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

24 Experts available now in Live!

Get 1:1 Help Now