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

Macros et VBA Excel Discussion :

créer un bouton depuis une macro


Sujet :

Macros et VBA Excel

  1. #1
    Nouveau candidat au Club
    Homme Profil pro
    Directeur commercial
    Inscrit en
    Janvier 2019
    Messages
    1
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Directeur commercial
    Secteur : Tourisme - Loisirs

    Informations forums :
    Inscription : Janvier 2019
    Messages : 1
    Par défaut créer un bouton depuis une macro
    Bonjour à tous

    J'ai un pb que je n'arrive pas à résoudre :

    J'ai créé une macro qui "fabrique" un commandbutton dans une nouvelle feuille. Jusque là, ça fonctionne bien. Ce que je ne sais pas faire, c'est lier ce commandbutton à une autre macro.
    Quelqu'un peut-il m'aider ?

    Merci à tous par avance et 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
    Private Sub CommandButton1_Click()
     
        'Ajouter une nouvelle feuille au nom du salarié
        With Sheets.Add
        .Name = ComboBox1.Value
        End With
     
     
        'création du tableau
        Sheets("Base").Range("P1:AW14").Copy Sheets(ComboBox1.Value).Range("A1")
        Columns("B:AF").Select
        Selection.ColumnWidth = 2.63
        'intégration des données du salarié dans le planning
        Range("b1") = "Planning annuel : " & ComboBox1.Value
        Range("A2") = ComboBox2.Value
     
     
        If ComboBox3.Value = "Janvier" Then
        Range("A3") = ComboBox3.Value
        ElseIf ComboBox3.Value = "Février" Then
        Range("A4") = ComboBox3.Value
        ElseIf ComboBox3.Value = "Mars" Then
        Range("A5") = ComboBox3.Value
        ElseIf ComboBox3.Value = "Avril" Then
        Range("A6") = ComboBox3.Value
        ElseIf ComboBox3.Value = "Mai" Then
        Range("A7") = ComboBox3.Value
        ElseIf ComboBox3.Value = "Juin" Then
        Range("A8") = ComboBox3.Value
        ElseIf ComboBox3.Value = "Juillet" Then
        Range("A9") = ComboBox3.Value
        ElseIf ComboBox3.Value = "Août" Then
        Range("A10") = ComboBox3.Value
        ElseIf ComboBox3.Value = "Septembre" Then
        Range("A11") = ComboBox3.Value
        ElseIf ComboBox3.Value = "Octobre" Then
        Range("A12") = ComboBox3.Value
        ElseIf ComboBox3.Value = "Novembre" Then
        Range("A13") = ComboBox3.Value
        ElseIf ComboBox3.Value = "Décembre" Then
        Range("A14") = ComboBox3.Value
        Else
        Range("A14") = ""
        End If
     
        no_ligne = Sheets("Base").Range("K65536").End(xlUp).Row + 1
        Sheets("Base").Cells(no_ligne, 11) = ComboBox1.Value
     
    Unload Me
     
        Range("A1").Select
     
    'AjoutCommandButton_Feuille()
            Dim Obj As OLEObject
     
     
            'Ajout CommandButton dans la feuille
            Set Obj = Sheets(ComboBox1.Value).OLEObjects.Add("Forms.CommandButton.1")
                With Obj
                .Left = 616 'position horizontale
                .Top = 230 'position verticale
                .Width = 140 'largeur
                .Height = 30 'hauteur
                .Object.BackColor = RGB(235, 235, 200) 'Couleur de fond
                .Object.Caption = "Fermer le planning"
                End With
     
    End Sub

  2. #2
    Invité
    Invité(e)
    Par défaut
    Bonjour,
    Ajoute à la création de ton bouton

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    .Objet.OnAction="Nom de la macro à lancer"

  3. #3
    Expert éminent Avatar de Menhir
    Homme Profil pro
    Ingénieur
    Inscrit en
    Juin 2007
    Messages
    16 037
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Finistère (Bretagne)

    Informations professionnelles :
    Activité : Ingénieur
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2007
    Messages : 16 037
    Par défaut
    Pour compléter la réponse de mimimathy ( ) :
    https://docs.microsoft.com/fr-fr/off...eobject.object
    https://docs.microsoft.com/fr-fr/off...shape.onaction

    Perso, pour créer un bouton, je passe tout simplement par une Form (Shape) qui permet beaucoup plus de possibilités graphiquement : on peut lui donner n'importe quelle forme (rond, rectangle, étoile, etc.), n'importe quelle couleur, police de caractère, etc.
    https://docs.microsoft.com/fr-fr/off...hapes.addshape
    Et il dispose de la propriété OnAction.

Discussions similaires

  1. créer dans excel un bouton avec une macro personnalisée
    Par deubelte dans le forum Macros et VBA Excel
    Réponses: 1
    Dernier message: 20/11/2008, 16h01
  2. [applet] créer un fichier depuis une applet.
    Par BouB dans le forum Applets
    Réponses: 12
    Dernier message: 02/04/2007, 06h45
  3. comment créer des boutons sur une feuille en utilisant eclipse
    Par ratamahatta dans le forum Eclipse Java
    Réponses: 1
    Dernier message: 09/06/2006, 19h17
  4. [VBA-E] Comment créer un bouton ds une wksheet par un code vba
    Par moicwill dans le forum Macros et VBA Excel
    Réponses: 3
    Dernier message: 29/05/2006, 17h12
  5. [excel] bouton pour une macro
    Par arcane dans le forum Macros et VBA Excel
    Réponses: 4
    Dernier message: 02/05/2006, 09h17

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