CommandbarButton Event not working (Wor, Vb.net)

T

TheXception

Hello,
i create a toolbar button this way:

Public Sub OnConnection(ByVal application As Object, ByVal connectMode
As Extensibility.ext_ConnectMode, ByVal addInInst As Object, ByRef
custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnConnection
applicationObject = application
_WordApplication = CType(application, Word.Application)
addInInstance = addInInst

_WordCommandBarsMail = CType(_WordApplication.CommandBars,
Microsoft.Office.Core.CommandBars)

_MainToolbarMail = CType(_WordCommandBarsMail.Add("TestAddin", , ,
True), Microsoft.Office.Core.CommandBar)
_MainToolbarMail.Visible = True
_MainToolbarMail.Position = MsoBarPosition.msoBarTop

_Button = CType(_MainToolbarMail.Controls.Add
(MsoControlType.msoControlButton),
Microsoft.Office.Core.CommandBarButton)
_Button.Style = MsoButtonStyle.msoButtonCaption
_Button.Caption = "TestAddin"
_Button.OnAction = "!<TestAddin.Connect>"
AddHandler _Button.Click, AddressOf buttonclick

End Sub

and:

Dim applicationObject As Object
Dim _MainToolbarMail As CommandBar
Dim _WordApplication As Word.Application

Dim addInInstance As Object
Dim _WordCommandBarsMail As CommandBars
Dim _Button As Microsoft.Office.Core.CommandBarButton

Public Sub buttonclick(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
Trace.WriteLine("[TestAddin] Button pressed")
End Sub

My problem now is, that he only triggers the OnClick event in the first
Word window i open. if i open a second document in this window the
button does not work. if i go back to the first document the button
works again.

TheXception
 
S

senthil

you need to specify unique Tag for each commandbarbutton
_Button.Tag = "CommandbarName"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top