W
wendy
I don't know if it is right group i paste, if not, pls point me to the
right one, thanks in advanced.
I created com add-in for word2003, excel2003 and powerpoint2003,
basically, i added 4 button in toobar, when button 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.
another word problem, i catch the event DocumentBeforeSave, how can i
tell it is saved by user intead of auto save.
code attached below,Any help and suggestion will be great appriciated
Wendy
<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 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_ClickEventHandler) _
As Microsoft.Office.Core.CommandBarButton
Try
Dim newButton As Microsoft.Office.Core.CommandBarButton
newButton = CType(commandBar.Controls.Add( _
Microsoft.Office.Core.MsoControlType.msoControlButton),
_
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
right one, thanks in advanced.
I created com add-in for word2003, excel2003 and powerpoint2003,
basically, i added 4 button in toobar, when button 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.
another word problem, i catch the event DocumentBeforeSave, how can i
tell it is saved by user intead of auto save.
code attached below,Any help and suggestion will be great appriciated
Wendy
<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 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_ClickEventHandler) _
As Microsoft.Office.Core.CommandBarButton
Try
Dim newButton As Microsoft.Office.Core.CommandBarButton
newButton = CType(commandBar.Controls.Add( _
Microsoft.Office.Core.MsoControlType.msoControlButton),
_
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