Bonjour,

Je suis actuellement en plein apprentissage du developpement d'add-in pour word. Et à ce propos j'ai suivi ce tutorial (http://lgmorand.developpez.com/dotnet/officeaddin/) qui m'a paru pertinent meme si écrit pour développer en c#.

POur l'instant j'arrive bien à créer un bouton dans ma commandbar mais rien ne se passe lorsque je clique sur le bouton alors que j'ai créé une procédure de type "click". Pour l'instant je veux juste faire apparaitre un simple message box...

Voici mon code:
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
imports Extensibility
Imports System.Runtime.InteropServices
Imports System
Imports Microsoft.Office.Core
Imports word = Microsoft.Office.Interop.Word
 
 
 
#Region " Read me for Add-in installation and setup information. "
' When run, the Add-in wizard prepared the registry for the Add-in.
' At a later time, if the Add-in becomes unavailable for reasons such as:
'   1) You moved this project to a computer other than which is was originally created on.
'   2) You chose 'Yes' when presented with a message asking if you wish to remove the Add-in.
'   3) Registry corruption.
' you will need to re-register the Add-in by building the $SAFEOBJNAME$Setup project, 
' right click the project in the Solution Explorer, then choose install.
#End Region
 
<GuidAttribute("57ABE57B-076D-49F0-A20E-2256AABA9080"), ProgIdAttribute("testAddin01.Connect")> _
Public Class Connect
    'first statement
    Implements Extensibility.IDTExtensibility2
 
    'Dim simpleButton As CommandBarButton 'create my personal button
 
    'Private applicationObject As Object
    'Private addInInstance As Object
    Private applicationObject As word.Application
    Private addInInstance As Microsoft.Office.Core.COMAddIn
    Private WithEvents app As word.Application
    Private WithEvents simpleButton As 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
 
        Dim CommandBars As CommandBars
        Dim Standardbar As CommandBar
        app = Me.applicationObject
        CommandBars = applicationObject.CommandBars
 
        ' Get the standard CommandBar from Word
        standardBar = CommandBars("Standard")
 
        Try
            ' try to reuse the button if it is not deleted
            simpleButton = CType(Standardbar.Controls( _
              "Superman"), CommandBarButton)
            MsgBox("boum")
        Catch
            ' If it is not there, add a new button
            simpleButton = CType(standardBar.Controls.Add(1),  _
              CommandBarButton)
            simpleButton.Caption = "Superman"
            simpleButton.Style = MsoButtonStyle.msoButtonCaption
        End Try
 
        ' Make sure the button is visible
        simpleButton.Visible = True
        simpleButton.Enabled = True
 
        standardBar = Nothing
        CommandBars = Nothing
 
        'simpleButton = Me.applicationObject
 
 
    End Sub
 
    Private Sub simpleButton_Click( _
   ByVal Ctrl As Microsoft.Office.Core.CommandBarButton, _
   ByRef CancelDefault As Boolean) Handles simpleButton.Click
        Dim findtext As Object = "courage"
 
        'MessageBox.Show("hello world")
 
        Dim rng As word.Range = Me.applicationObject.ActiveDocument.Paragraphs(1).Range
        rng.Find.ClearFormatting()
 
        If rng.Find.Execute(findtext) Then
            MessageBox.Show("Text found.")
        Else
            MessageBox.Show("Text not found.")
        End If
 
        rng.Select()
 
    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
        applicationObject = CType(application,  _
      word.Application)
 
        addInInstance = CType(addInInst,  _
          Microsoft.Office.Core.COMAddIn)
 
 
    End Sub
 
End Class
La procédure OnStartupComplete crée le bouton et l'initialise alors que la fonction simpleButton_Click devrait gérer mon code fonctionnel.

Merci d'avance pour votre aide