Solved

VB.net Excel Add-in

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.

776 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