Hi David,
With Excel-DNA you have full access to the Excel COM Automation interfaces. So anything that you can do in VBA can also be done in and Excel-DNA add-in (and more).
I've made a small example that shows how this might work. These instructions might work (if the stars are well aligned):
* Create a new Visual Basic Class Library project in Visual Studio.
* Add the following NuGet Packages: "Excel-DNA", and "Excel-DNA.Interop". IN the Nuget dialog the second one is called "Excel-DNA - Primary Interop Assemblies for Excel 2010.
* Replace all the code in Class1.vb with the code pasted below.
* Press F5 to compile and run, then look for the selections changes to be displayed in the status bar, and try the cell context menu.
If anything goes wrong, write back and we can try to figure it out.
-Govert
'--------------------------------------
Imports Microsoft.Office.Interop.Excel
Imports Microsoft.Office.Core
Imports ExcelDna.Integration
Public Module MyFunctions
<ExcelFunction(Description:="My first .NET function")> _
Public Function dnaHello(name As String) As String
Return "Hello " & name
End Function
End Module
Public Class AddIn
Implements IExcelAddIn
WithEvents Application As Application
WithEvents Button As CommandBarButton
Public Sub AutoOpen() Implements IExcelAddIn.AutoOpen
Application = ExcelDnaUtil.Application
' Add Cell context menu
Dim ContextMenu As CommandBar
ContextMenu = Application.CommandBars("Cell")
Button = ContextMenu.Controls.Add(Type := MsoControlType.msoControlButton, Before := ContextMenu.Controls.Count, Temporary := true)
With Button
.Caption = "Excel-DNA Test Button"
.Tag = "EXCEL-DNA-Test"
End With
End Sub
Public Sub AutoClose() Implements IExcelAddIn.AutoClose
Button.Delete
End Sub
Private Sub Application_SheetSelectionChange(Sh As Object, Target As Range) Handles Application.SheetSelectionChange
Application.StatusBar = "Selection on sheet " + CType(Sh, Worksheet).Name & " is now " & Target.Address
End Sub
Private Sub Button_Click(Ctrl As CommandBarButton, ByRef CancelDefault As Boolean) Handles Button.Click
Application.StatusBar = "Excel-DNA Test Button - Clicked!"
End Sub
End Class