IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB.NET Discussion :

[add-in office] évènement au click


Sujet :

VB.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    33
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 33
    Par défaut [add-in office] évènement au click
    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

  2. #2
    Membre Expert
    Avatar de supersnail
    Homme Profil pro
    Inscrit en
    Novembre 2006
    Messages
    1 719
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Novembre 2006
    Messages : 1 719
    Par défaut
    Il faudrait peut-être attacher ta fonction à l'évènement du bouton... (les miracles n'existent pas..)

  3. #3
    Membre averti
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    33
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 33
    Par défaut
    Cette déclaration ne déclare t-elle pas l'évènement?

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    Private WithEvents simpleButton As CommandBarButton
    Par ailleurs je rattache un handle de type simpleButton.Click et il me semble que cela sert à gerer l'évènement.

    sinon je vois pas comment rattacher la fonction à l'èvenement du bouton

  4. #4
    Membre averti
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    33
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 33
    Par défaut
    Bon bah nouveauté, mon code fonctionne pour les add-ins de powerpoint et excel...

    C'est bizarre, quelqu'un aurait -il une idée?

Discussions similaires

  1. [add-in Office] Technique pour capturer l'évènement Enregistrer
    Par steph_ch dans le forum Général Dotnet
    Réponses: 2
    Dernier message: 08/07/2008, 14h52
  2. Réponses: 4
    Dernier message: 29/09/2006, 09h35
  3. Réponses: 19
    Dernier message: 21/03/2006, 19h56
  4. événement on click
    Par Elo13 dans le forum Balisage (X)HTML et validation W3C
    Réponses: 2
    Dernier message: 28/09/2005, 10h05
  5. événement on click
    Par Elo13 dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 28/09/2005, 10h04

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo