Matthew,
If You place a breakpoint in the code and step through the code can You see if the code does anything wrong?
Could You please give us which version of VSTO You use and also which Excel version You work with.
Below is the expanded code based on the first thread where I have added the events and Windows Forms. It works as expected:
Public Class ThisAddIn
Private WithEvents MyButtonA As Office.CommandBarButton
Private WithEvents MyButtonB As Office.CommandBarButton
Private Sub ThisAddIn_Startup(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Startup
' Start of VSTO generated code
Me.Application = CType(Microsoft.Office.Tools.Excel.ExcelLocale1033Proxy.Wrap(GetType(Excel.Application), Me.Application), Excel.Application)
' End of VSTO generated code
Dim cbMain As Office.CommandBar = Application.CommandBars(1)
Dim oCtl As Office.CommandBarPopup = CType(cbMain.Controls.Add(Office.MsoControlType.msoControlPopup, Temporary:=True), Office.CommandBarPopup)
Try
With oCtl
.Tag = "MyAddin"
.Caption = "ExcelGroup"
MyButtonA = CType(.Controls.Add(Type:=Office.MsoControlType.msoControlButton), Office.CommandBarButton)
With MyButtonA
.BeginGroup = True
.Caption = "My 1st Procedure"
.FaceId = 296
.Style = Office.MsoButtonStyle.msoButtonIconAndCaption
End With
MyButtonB = CType(.Controls.Add(Type:=Office.MsoControlType.msoControlButton), Office.CommandBarButton)
With MyButtonB
.BeginGroup = True
.Caption = "My 2nd Procedure"
.FaceId = 298
.Style = Office.MsoButtonStyle.msoButtonIconAndCaption
End With
End With
Catch ex As Exception
MessageBox.Show(ex.ToString, My.Application.Info.Title.ToString)
Finally
oCtl = Nothing
cbMain = Nothing
End Try
End Sub
Private Sub ThisAddIn_Shutdown(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Shutdown
Dim oCtl As Office.CommandBarControl
Try
For Each oCtl In Application.CommandBars.FindControls(Tag:="MyAddin")
oCtl.Delete()
Exit For
Next
Catch ex As Exception
'Skip
Finally
oCtl = Nothing
End Try
End Sub
Private Sub MyButtonA_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles MyButtonA.Click
Dim frm As New frm1
Try
frm.Show()
Catch ex As Exception
End Try
End Sub
Private Sub MyButtonB_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles MyButtonB.Click
Dim frm As New frm2
Try
frm.Show()
Catch ex As Exception
End Try
End Sub
End Class
With kind regards,
Dennis W
--------------------------------------------------------------
My English Excel site My VSTO & .NET & Excel blog