I've created a shared addin for Word 2003 in VS 2005 with has a strange habit.
The shared addin creates a commanbar. Everything is working fine, except
that the buttons won't fire if you add new documents in Word. Only in the
available empty document or the last the buttons work, so:
Start Word, only one empty document1 is open, buttons work fine.
Add document by choosing file new -> Document2, buttons don't work in
document2, but in document1.
Close document1, buttons do work in document2.
Who can explain this and more wanted: solve this.
The code for reconstruction: build a addin for Word, keep everthing default
and create this code in Connect.vb
Private wrdApp As Word.Application (instead of applicationObject as
Object)
Private mBar As CommandBar
Private mBarPopup As CommandBarPopup
Private WithEvents mbarbtnAbout As CommandBarButton
Public Sub OnDisconnection(ByVal RemoveMode As
Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements
Extensibility.IDTExtensibility2.OnDisconnection
mBar.Delete()
End Sub
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
wrdApp = CType(application, Word.Application)
mBar = wrdApp.CommandBars.Add("TEST", , , True)
mBarPopup =
CType(mBar.Controls.Add(Type:=MsoControlType.msoControlPopup, Before:=1,
Temporary:=True), CommandBarPopup)
mBarPopup.Caption = "Test"
mbarbtnAbout =
CType(mBarPopup.Controls.Add(MsoControlType.msoControlButton, , , , True),
CommandBarButton)
mbarbtnAbout.OnAction = "!<MyAddin1.Connect>"
mbarbtnAbout.Caption = "Click"
mBar.Visible = True
End Sub
Private Sub mbarbtnAbout_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean)
Handles mbarbtnAbout.Click
MsgBox("Clicked")
End Sub
VictorH - 13 Apr 2006 09:42 GMT
I think I found it myself,
If you add a tag to the buttons, everything seems to work fine..... strange.
> I've created a shared addin for Word 2003 in VS 2005 with has a strange habit.
> The shared addin creates a commanbar. Everything is working fine, except
[quoted text clipped - 49 lines]
> MsgBox("Clicked")
> End Sub