471,119 Members | 1,567 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,119 software developers and data experts.

problem with events CommandBarButton.click in Word

I have to create a small addin which works on Powerpoint, Word, Outlook, and Excel on Office 2000, XP, and 2003.
This addin consists in adding 2 new Buttons in the "File" Menu of office. This is properly done, but the events which should be triggered with the button.click method are not triggered in Word.
I don't understand because it properly works in the 3 others host applications.
If someone has an issue, I would be most grateful.

here is the code of my connect.vb file:

__________________________________________________ __

Imports Microsoft.Office.Core
' importe les objets nénécessaires * la construction des menus ou autres outils
' au sein de microsoft office

Imports Extensibility
' importe l'interface IDTExtensibility2, et les objets nécessaires *
' la "connection" de l'addin * l'application hôte

Imports System.Runtime.InteropServices

#Region " Lisez Moi pour avoir des infos sur l'installation de l'addin sur d'autres postes. "
' Dans la fenetre Solution Explorer de Visual Studio .NET 2003, il faut:
' * click droit sur <nomDuProjet> ; et choisir "build" .
' * click droit sur <nomDuProjet>Setup ; et choisir "build" .
' * Sur l'autre poste :
' ** copier le répertoire du projet en cours.
' ** executer (dans ce répertoire) /MyCOMAddinSetup/debug/setup .
' ** ouvrir une des applications hôte.
#End Region

' classe connect: classe qui lance l'execution de l'addin a chaque lancement
' de l'application hôte. Cette classe implémente l'interface IDTExtensibility2

<GuidAttribute("8EFC12FE-8F9C-4802-88B0-56F297E844E0"), ProgIdAttribute("MyCOMAddin.Connect")> _
Public Class Connect

Implements IDTExtensibility2

Dim applicationObject As Object
Dim addInInstance As Object
Dim WithEvents workitSave As CommandBarButton
Dim WithEvents workitSaveAs As CommandBarButton

Public Sub OnBeginShutdown(ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnBeginShutdown
On Error Resume Next
' Notify the user you are shutting down, and delete the button.
MsgBox("Our custom Add-in is unloading.")

workitSave = applicationObject.CommandBars.FindControl(Tag:="wo rkit save")
workitSave = Nothing

workitSaveAs = applicationObject.CommandBars.FindControl(Tag:="wo rkit save as")
workitSaveAs = Nothing

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

Dim oCommandBars As CommandBars

On Error Resume Next

oCommandBars = applicationObject.CommandBars
If oCommandBars Is Nothing Then
' Outlook has the CommandBars collection on the Explorer object.
oCommandBars = applicationObject.ActiveExplorer.CommandBars
End If
workitSave = oCommandBars("File").Controls.Item("workit save")
If workitSave Is Nothing Then
workitSave = oCommandBars("File").Controls.Add(Type:=MsoControl Type.msoControlButton, Id:=1)
workitSave.Caption = "workit save"
workitSave.TooltipText = "workit save"
workitSave.Tag = "workit save"
workitSave.Style = MsoButtonStyle.msoButtonCaption
workitSave.OnAction = "!<MyCOMAddin.Connect>"
End If

workitSaveAs = oCommandBars("File").Controls.Item("workit save as")
If workitSaveAs Is Nothing Then
workitSaveAs = oCommandBars("File").Controls.Add(Type:=MsoControl Type.msoControlButton, Id:=1)
workitSaveAs.Caption = "workit save as"
workitSaveAs.TooltipText = "workit save as"
workitSaveAs.Tag = "workit save as"
workitSaveAs.Style = MsoButtonStyle.msoButtonCaption
workitSaveAs.OnAction = "!<MyCOMAddin.Connect>"
End If

' Display a simple message to show which application you started in.
MsgBox("Started in " & applicationObject.Name & ".")
oCommandBars = Nothing
End Sub

Public Sub OnDisconnection(ByVal RemoveMode As Extensibility.ext_DisconnectMode, ByRef custom As System.Array) Implements Extensibility.IDTExtensibility2.OnDisconnection

On Error Resume Next
If RemoveMode <> Extensibility.ext_DisconnectMode.ext_dm_HostShutdo wn Then _
Call OnBeginShutdown(custom)

applicationObject = Nothing
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
MsgBox("On Connection In MyAddin")
applicationObject = application
addInInstance = addInInst
' If you aren't in startup, manually call OnStartupComplete.
If (connectMode <> Extensibility.ext_ConnectMode.ext_cm_Startup) Then _
Call OnStartupComplete(custom)

End Sub
Private Sub workitSave_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles workitSave.Click
MsgBox("vous voulez sauver ds workit")
End Sub

Private Sub workitSaveAs_Click(ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, ByRef CancelDefault As Boolean) Handles workitSaveAs.Click
MsgBox("vous voulez sauver ds workit mais sous un autre nom")
End Sub

End Class
__________________________________________________ _____
it's a very simple code that make the same mistake on every configuration of PC I tried.
Nov 20 '05 #1
0 2967

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by teb | last post: by
3 posts views Thread by Thiago Arrais | last post: by
reply views Thread by Galin iliev | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.