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
Wendy
Imports Office = Microsoft.Office.Core
Imports Extensibility
Imports System.Runtime.InteropServices

Imports Word = Microsoft.Office.Interop.Word

<GuidAttribute("BF60D3CC-02A1-42f5-B17D-1965D13E7BB7"),
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
Extensibility.IDTExtensibility2.OnAddInsUpdate
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
Extensibility.IDTExtensibility2.OnConnection
applicationObject = application
addInInstance = addInInst
Setup(application)

If Not application Is Nothing Then
FEToolbar = AddToolBar(application, "RM Office 2003
Activator.")
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
Boolean
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
Try
Dim newButton As Microsoft.Office.Core.CommandBarButton
newButton = CType(commandBar.Controls.Add( _
Microsoft.Office.Core.MsoControlType.msoControlBut ton),
_
Microsoft.Office.Core.CommandBarButton)
newButton.Caption = caption
newButton.FaceId = faceID
newButton.DescriptionText = "My button"
newButton.Style =
Office.MsoButtonStyle.msoButtonCaption
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.