By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,948 Members | 816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,948 IT Pros & Developers. It's quick & easy.

button Click event triggerd twice in com add-in word 2003

P: n/a
I created com add-in for word2003, excel2003 and powerpoint2003,
basically, i added 4 button in toobar and on_click, i apply some
bussiness logic. all works in excel2003 and powerpoint 2003, but in
word2003, the button event has been tiggered twice. After i click, it
run the code inside the button click, then run again. so annoying.

code attached below,Any help and suggestion will be great appriciated
Imports Office = Microsoft.Office.Core
Imports Extensibility
Imports System.Runtime.InteropServices

Imports Word = Microsoft.Office.Interop.Word

ProgIdAttribute("Office_AddIn.ConnectWord")> _
Public Class ConnectWord
Implements Extensibility.IDTExtensibility2

Dim applicationObject As Object
Dim addInInstance As Object

Private Shared WithEvents FEWordApplication As Word.Application

Dim FEToolbar As Microsoft.Office.Core.CommandBar = Nothing

Private WithEvents BtnEventsOptions As Office.CommandBarButton
Private WithEvents BtnEventsClassify As Office.CommandBarButton
Public Sub OnBeginShutdown(ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnBeginShutdown
End Sub

Public Sub OnAddInsUpdate(ByRef custom As System.Array) Implements
End Sub

Public Sub OnStartupComplete(ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnStartupComplete
End Sub

Public Sub OnDisconnection(ByVal RemoveMode As
Extensibility.ext_DisconnectMode, ByRef custom As System.Array)
Implements Extensibility.IDTExtensibility2.OnDisconnection
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
applicationObject = application
addInInstance = addInInst

If Not application Is Nothing Then
FEToolbar = AddToolBar(application, "RM Office 2003
End If

BtnEventsClassify = MakeANewButton(FEToolbar, "RM Classify",
0, _
AddressOf BtnEventsClassify_Click)
BtnEventsClassify.Tag = "word_classity"

BtnEventsOptions = MakeANewButton(FEToolbar, "RM Options", 0, _
AddressOf BtnEventsOptions_Click)
BtnEventsOptions.Tag = "word_options"

End Sub

Public Shared Function Setup(ByVal oApp As Word.Application) As
FEWordApplication = oApp
End Function
Private Sub p_ctlBtnEventsOptions_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As
Boolean) Handles p_ctlBtnEventsOptions.Click
MsgBox("I am in Option_click")

End Sub

Private Sub p_ctlBtnEventsClassify_Click(ByVal Ctrl As
Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As
Boolean) Handles p_ctlBtnEventsClassify.Click

MsgBox("I am in Classity_click")

End Sub

End Class

Public Function MakeANewButton(ByVal commandBar As _
Microsoft.Office.Core.CommandBar, ByVal caption As String, _
ByVal faceID As Integer, ByVal clickHandler As _
Microsoft.Office.Core._CommandBarButtonEvents_Clic kEventHandler) _
As Microsoft.Office.Core.CommandBarButton
Dim newButton As Microsoft.Office.Core.CommandBarButton
newButton = CType(commandBar.Controls.Add( _
Microsoft.Office.Core.MsoControlType.msoControlBut ton),
newButton.Caption = caption
newButton.FaceId = faceID
newButton.DescriptionText = "My button"
newButton.Style =
AddHandler newButton.Click, clickHandler
Return newButton
Catch ex As System.Exception
Return Nothing
End Try
End Function
Jul 21 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.