Bonjour,
En aide à un forumeur, je me trouve exposé à un problème que je ne saisis pas... J'ai beau chercher, m'arracher les cheveux, rien n'y fait. Je fais donc appel àvos lumières. Merci de vous pencher sur ce cas...
Voici ce que j'ai fait (et qui ne fonctionne pas!)

Dans un module standard :
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
Public Bouton() As New Classe1
Dim Obj As OLEObject
 
Sub CreateButton()
Worksheets("Principal").Select
Set Obj = ActiveSheet.OLEObjects.Add("Forms.CommandButton.1", Left:=100, Top:=150, Width:=80, Height:=30)
With Obj
    .Name = "ButtonInitFeuille"
    .Object.Caption = "Initialisation"
End With
InitBoutons
End Sub
 
Sub InitBoutons()
Dim Cpt As Integer
 
For Each Obj In Worksheets("Principal").OLEObjects
    'If oleObj.Name = "ButtonInitFeuille" Then
    If TypeOf Obj.Object Is MSForms.CommandButton Then
        Cpt = Cpt + 1
        ReDim Preserve Bouton(1 To Cpt)
        Set Bouton(Cpt).ButtonInitFeuille = Obj.Object
   End If
Next
Set Obj = Nothing
End Sub
 
Sub InitFeuilleTab()
    MsgBox "Ca fonctionne!"
End Sub
Dans le module de classe (nommé Classe1) :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
Option Explicit
 
Public WithEvents ButtonInitFeuille As MSForms.CommandButton
 
Private Sub ButtonInitFeuille_Click()
    Call InitFeuilleTab
End Sub
Voilà. Lorsque je créé un bouton en lançant "CreateButton", il le créé bien. Cependant, le clic n'a aucun effet. Pour obtenir un résultat, il faut lancer "CreateButton" puis, manuellement (ALT+F8) "InitBoutons"... J'en perds mon lâtin.
Merci.
Vous dites, si vous voulez un classeur exemple ou de plus amples indications...