Probleme avec code et bouton

Boostez vos compétences Excel avec notre communauté !

Rejoignez Excel Downloads, le rendez-vous des passionnés où l'entraide fait la force. Apprenez, échangez, progressez – et tout ça gratuitement ! 👉 Inscrivez-vous maintenant !

Scrunchy

XLDnaute Nouveau
Bonjour

voici mon pb, j'ai créé un fichier xl automatiquement depuis un fichier xl qui importe des fichiers csv. J'ai mis sur ma feuille de resultat des boutons mais je n'arrive pas à creer les codes associés à ces boutons!!
Pouvez vous m'aider?..

voici le code pour creer les boutons..

------------------------------------------------------------
Sub Page2garde()
Sheets(1).Select
Sheets.Add
Sheets(1).Name = P2G

Sheets(NSB1).Select
Range("A1:K2").Copy
Sheets(P2G).Select
Range("C2:M2").Select
Selection.Insert Shift:=xlDown
Selection.Font.Bold = True

Range("C2:M3").Select
Call couleurJaune
Call miseenforme
Call centrer

Range("D6").Select
ActiveCell.FormulaR1C1 = "Nombre De Bloomberg Declaré : "
Selection.Font.Bold = True
Call centrer

Range("E6").Select
ActiveCell.FormulaR1C1 = decl
Selection.Font.Bold = True
Call centrer

Range("G6").Select
ActiveCell.FormulaR1C1 = "Nombre De Bloomberg : "
Call centrer

Range("H6").Select
ActiveCell.FormulaR1C1 = TBloom
Call centrer

Columns("A:Z").EntireColumn.AutoFit

'##################Serie1##################
'ComboBox1
ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1", Link:=False, _
DisplayAsIcon:=False, Left:=60, Top:=112, Width:=153, Height:= _
18).Select

'Chargement Combobox1 SID
SidI = 4
While Worksheets("Tri" & NSB2).Cells(SidI, 3) <> ""
ActiveSheet.OLEObjects("Combobox1").Object.AddItem Worksheets("Tri" & NSB2).Cells(SidI, 3)
SidI = SidI + 1
Wend

'Label1
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Label.1", Link:=False _
, DisplayAsIcon:=False, Left:=125, Top:=97, Width:=21, Height:= _
12).Select
ActiveSheet.OLEObjects("Label1").Object.Font.Bold = True
ActiveSheet.OLEObjects("Label1").Object.Caption = "SID"

'Bouton1
ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
, DisplayAsIcon:=False, Left:=107, Top:=133, Width:=54, Height:= _
23).Select
ActiveSheet.OLEObjects("CommandButton1").Object.Caption = "GO"

'##################Serie2##################
'ComboBox2
ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1", Link:=False, _
DisplayAsIcon:=False, Left:=235, Top:=112, Width:=153, Height:= _
18).Select

'Chargement Combobox2 SN/UUID
SidI = 4
While Worksheets("Tri" & NSB2).Cells(SidI, 12) <> ""
ActiveSheet.OLEObjects("Combobox2").Object.AddItem Worksheets("Tri" & NSB2).Cells(SidI, 12)
SidI = SidI + 1
Wend

'Label2
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Label.1", Link:=False _
, DisplayAsIcon:=False, Left:=300, Top:=97, Width:=50, Height:= _
12).Select
ActiveSheet.OLEObjects("Label2").Object.Font.Bold = True
ActiveSheet.OLEObjects("Label2").Object.Caption = "SN-UUID"

'Bouton2
ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
, DisplayAsIcon:=False, Left:=286, Top:=133, Width:=54, Height:= _
23).Select
ActiveSheet.OLEObjects("CommandButton2").Object.Caption = "GO"

'##################Serie3##################
'ComboBox3
ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1", Link:=False, _
DisplayAsIcon:=False, Left:=413, Top:=112, Width:=153, Height:= _
18).Select

'Chargement Combobox3 User
SidI = 4
While Worksheets("Tri" & NSB2).Cells(SidI, 7) <> ""
If Worksheets("Tri" & NSB2).Cells(SidI, 7) <> Worksheets("Tri" & NSB2).Cells(SidI + 1, 7) Then
ActiveSheet.OLEObjects("Combobox3").Object.AddItem Worksheets("Tri" & NSB2).Cells(SidI, 7)
End If
SidI = SidI + 1
Wend

'Label3
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Label.1", Link:=False _
, DisplayAsIcon:=False, Left:=480, Top:=97, Width:=50, Height:= _
12).Select
ActiveSheet.OLEObjects("Label3").Object.Font.Bold = True
ActiveSheet.OLEObjects("Label3").Object.Caption = "User"

'Bouton3
ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
, DisplayAsIcon:=False, Left:=466, Top:=133, Width:=54, Height:= _
23).Select
ActiveSheet.OLEObjects("CommandButton3").Object.Caption = "GO"

'##################Serie4##################
'ComboBox4
ActiveSheet.OLEObjects.Add(ClassType:="Forms.ComboBox.1", Link:=False, _
DisplayAsIcon:=False, Left:=585, Top:=112, Width:=273, Height:= _
18).Select

'Chargement Combobox4 Bourses
SidI = 22
While Worksheets("Tri" & NSB3).Cells(SidI, 3) <> ""
If Worksheets("Tri" & NSB3).Cells(SidI, 3) <> Worksheets("Tri" & NSB3).Cells(SidI + 1, 3) Then
ActiveSheet.OLEObjects("Combobox4").Object.AddItem Worksheets("Tri" & NSB3).Cells(SidI, 3) & Migouel

ElseIf Worksheets("Tri" & NSB3).Cells(SidI, 4) <> "" Then
Migouel = " " & Worksheets("Tri" & NSB3).Cells(SidI, 4)
End If
SidI = SidI + 1
Wend

'Label4
ActiveSheet.OLEObjects.Add(ClassType:="Forms.Label.1", Link:=False _
, DisplayAsIcon:=False, Left:=702, Top:=97, Width:=50, Height:= _
12).Select
ActiveSheet.OLEObjects("Label4").Object.Font.Bold = True
ActiveSheet.OLEObjects("Label4").Object.Caption = "Bourses"

'Bouton4
ActiveSheet.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False _
, DisplayAsIcon:=False, Left:=690, Top:=133, Width:=54, Height:= _
23).Select
ActiveSheet.OLEObjects("CommandButton4").Object.Caption = "GO"
'Call EcritSUB
End Sub
------------------------------------------------------------

ceci n'est qu'une partie du code...

merci à vous de m'aider....
Benoît
 
Re : Probleme avec code et bouton

Bonjour,

Une piste avec le code suivant à copier dans un module standard.

CELA FAIT
1) création d'un CommandButton sur la feuille active
2) création du code évènementiel dans la page de code de la feuille active

ATTENTION
Pour que cela fonctionne il est IMPERATIF de faire
1) dans Excel et dans la barre d'outils Visual Basic cliquez sur "Sécurité…"
2) sélectionnez l'onglet "Editeurs approuvés"
3) cochez la case "Faire confiance au projet Visual Basic"

Faites l'essai sur un nouveau classeur.
************************
Sub CreeBoutonPlusCode()
Dim OLO As OLEObject
Dim VBC '''As VBIDE.VBComponent
Dim A$

Set OLO = ActiveSheet.OLEObjects.Add( _
ClassType:="Forms.CommandButton.1", _
Link:=False, DisplayAsIcon:=False, _
Left:=107, Top:=133, _
Width:=54, Height:=23)
With OLO
.Name = "MonBouton36" 'renommé pour éviter les conflits
.Object.Caption = " GO"
'--- Eventuels autres trucs ---
.Shadow = True
.Interior.ColorIndex = 3
'--- etc ---
End With

'### code du bouton ###
Set VBC = ActiveWorkbook.VBProject.VBComponents(ActiveSheet.CodeName)
A$ = vbCrLf & "Private Sub " & OLO.Name & "_Click()" & _
vbCrLf & "MsgBox ""coucou""" & _
vbCrLf & "End Sub"
VBC.CodeModule.AddFromString A$
End Sub
************************

Cordialement.

PMO
Patrick Morange
 
- Navigue sans publicité
- Accède à Cléa, notre assistante IA experte Excel... et pas que...
- Profite de fonctionnalités exclusives
Ton soutien permet à Excel Downloads de rester 100% gratuit et de continuer à rassembler les passionnés d'Excel.
Je deviens Supporter XLD

Discussions similaires

Réponses
16
Affichages
2 K
Réponses
1
Affichages
1 K
Réponses
8
Affichages
1 K
Retour