since several days I am searching for a solution, but I always get nearly the code for my problem. I want to create several buttons within Outlook via VisualStudio. These buttons should execute the same sub. But when I create the buttons with the shown code, only the last created button handles the click-event.
I'm using VisualStudio (15.0) and Outlook (16.0, 32bit)
Many thanks for your help
Holger
Public Class ThisAddIn
Dim ButtonControl As Office.CommandBarButton
Dim menuBar As Office.CommandBar
Dim newMenuBar As Office.CommandBarPopup
Private Sub ThisAddIn_Startup() Handles Me.Startup
Dim i As Integer
menuBar = Me.Application.ActiveExplorer().CommandBars.ActiveMenuBar
newMenuBar = menuBar.Controls.Add(Office.MsoControlType.msoControlPopup, Temporary:=True)
If newMenuBar IsNot Nothing Then
newMenuBar.Caption = "Mailverschiebung"
For i = 0 To 3
ButtonControl = newMenuBar.Controls.Add
ButtonControl.Caption = "zeichen" & i
ButtonControl.Tag = "zeichen" & i
AddHandler ButtonControl.Click, AddressOf ButtonControl_Click
Next
End If
End Sub
Sub ButtonControl_Click()
MsgBox("Läuft")
End Sub
Private Sub ThisAddIn_Shutdown() Handles Me.Shutdown
End Sub
End Class