Solved

VB.net Excel Add-in

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

Technology Partners: 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

You need to know the location of the Office templates folder, so that when you create new templates, they are saved to that location, and thus are available for selection when creating new documents.  The steps to find the Templates folder path are …
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

733 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