Should be possible. Here's how I did it in Excel VBA:
- Sub aBook()
-
'This Macro creates a workbook, a button, and a code module
-
Dim wb As Workbook
-
Dim ws As Worksheet
-
Dim s As Variant
-
Dim btn As OLEObject
-
Dim lLines As Long
-
' Hide VBE Window = No screen flashes
-
Application.VBE.MainWindow.Visible = False
-
' Create a new Workbook with one worksheet, Cmds
-
Set wb = Workbooks.Add
-
Set ws = Worksheets.Add
-
ws.Name = "Cmds"
-
Application.DisplayAlerts = False
-
For Each s In wb.Worksheets ' Delete the rest of the worksheets
-
If s.Name <> "Cmds" Then s.Delete
-
Next s
-
Application.DisplayAlerts = True
-
-
' Create a button
-
Set btn = ws.OLEObjects.Add(ClassType:="Forms.CommandButton.1", _
-
Left:=50, Top:=25, Width:=75, Height:=20)
-
btn.Name = "cmdWork"
-
btn.Object.Caption = "Press"
-
-
' Find the associated code module and create the click event handler
-
For Each s In wb.VBProject.VBComponents
-
If s.Name = ws.CodeName Then
-
With s.CodeModule
-
lLines = .CountOfLines
-
.InsertLines lLines + 1, "Sub cmdWork_Click()"
-
.InsertLines lLines + 2, " MsgBox ""Back to Work!"""
-
.InsertLines lLines + 3, "End Sub"
-
End With
-
Exit For
-
End If
-
Next s
-
End Sub
Obviously, you have some translation to do.
But, I have had a lot of trouble trying to do the stuff you have already done. Can you outline the steps to creating the Addin with C# 2005? I want to add a dialog box. I could do it with VB6, but am stuck with .Net.