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

pb: event Word click addin menu "File" button

P: n/a
Hello

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.
Thanks

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.Delete()
applicationObject.NormalTemplate.Save()
workitSave = Nothing

workitSaveAs = applicationObject.CommandBars.FindControl(Tag:="wo rkit save as")
workitSaveAs.Delete()
applicationObject.NormalTemplate.Save()
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.
Thanks

Nov 20 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.