J'ai écrit le projet ci-bas et lorsque mon code arrive à:
With ThisWorkbook.VBProject.VBComponents(ActiveWorkbook.ActiveSheet.Name).CodeModule
x = .CountOfLines + 1
.InsertLines x, laMacro
End With
j'arrive à une erreur disant que l'indice n'appartient pas à la sélection.
1. Pourquoi?
2. Est-il possible de débogguer un bouton? J'ai voulu mettre des points d'arrêts mais Excel semble y être allergique lorsqu'on parle de bouton.
3. Est-ce qu'on pourrait me suggérer une bonne façon de gérer mes largeurs de colonnes et hauteur de ligne pour mes boutons?
Sub CreerBouton()
Dim CaseBouton As String
Dim ModificateurHauteurDeLigne As Integer
Dim ModificateurLargeurDeColonne As Integer
Dim ColonneBouton As String
Dim Ws As Worksheet
Dim Obj As OLEObject
Dim laMacro As String
Dim x As Integer
ModificateurHauteurDeLigne = 1.5
ModificateurLargeurDeColonneBouton = 31
ColonneBouton = "D"
W = 140
H = 0
L = 0
T = 0
CaseBouton = Cells(1, 4).Select
H = ActiveCell.Height * ModificateurHauteurDeLigne
L = ActiveCell.Left
T = ActiveCell.Top
'Worksheet 'Ajout CommandButton dans la feuille
Set Obj = ActiveWorkbook.ActiveSheet.OLEObjects.Add("Forms.CommandButton.1")
With Obj
.Left = L 'position horizontale
.Top = T 'position verticale
.Width = W 'largeur
.Height = H 'hauteur
.Object.BackColor = RGB(235, 235, 200) 'Couleur de fond
.Object.Caption = "qpw502.prodna.mrqech"
End With
'Paramètres pour la création de la macro:
laMacro = "Sub CommandButton1_Click()" & vbCrLf
laMacro = laMacro & "X" & vbCrLf
laMacro = laMacro & "End Sub"
With ThisWorkbook.VBProject.VBComponents(ActiveWorkbook.ActiveSheet.Name).CodeModule
x = .CountOfLines + 1
.InsertLines x, laMacro
End With
Columns(ColonneBouton & ":" & ColonneBouton).ColumnWidth = 31
Rows("1:1").RowHeight = H
End Sub
Sub Tester()
MsgBox "Vous avez cliquez sur le bouton test"
End Sub
With ThisWorkbook.VBProject.VBComponents(ActiveWorkbook.ActiveSheet.Name).CodeModule
x = .CountOfLines + 1
.InsertLines x, laMacro
End With
j'arrive à une erreur disant que l'indice n'appartient pas à la sélection.
1. Pourquoi?
2. Est-il possible de débogguer un bouton? J'ai voulu mettre des points d'arrêts mais Excel semble y être allergique lorsqu'on parle de bouton.
3. Est-ce qu'on pourrait me suggérer une bonne façon de gérer mes largeurs de colonnes et hauteur de ligne pour mes boutons?
Sub CreerBouton()
Dim CaseBouton As String
Dim ModificateurHauteurDeLigne As Integer
Dim ModificateurLargeurDeColonne As Integer
Dim ColonneBouton As String
Dim Ws As Worksheet
Dim Obj As OLEObject
Dim laMacro As String
Dim x As Integer
ModificateurHauteurDeLigne = 1.5
ModificateurLargeurDeColonneBouton = 31
ColonneBouton = "D"
W = 140
H = 0
L = 0
T = 0
CaseBouton = Cells(1, 4).Select
H = ActiveCell.Height * ModificateurHauteurDeLigne
L = ActiveCell.Left
T = ActiveCell.Top
'Worksheet 'Ajout CommandButton dans la feuille
Set Obj = ActiveWorkbook.ActiveSheet.OLEObjects.Add("Forms.CommandButton.1")
With Obj
.Left = L 'position horizontale
.Top = T 'position verticale
.Width = W 'largeur
.Height = H 'hauteur
.Object.BackColor = RGB(235, 235, 200) 'Couleur de fond
.Object.Caption = "qpw502.prodna.mrqech"
End With
'Paramètres pour la création de la macro:
laMacro = "Sub CommandButton1_Click()" & vbCrLf
laMacro = laMacro & "X" & vbCrLf
laMacro = laMacro & "End Sub"
With ThisWorkbook.VBProject.VBComponents(ActiveWorkbook.ActiveSheet.Name).CodeModule
x = .CountOfLines + 1
.InsertLines x, laMacro
End With
Columns(ColonneBouton & ":" & ColonneBouton).ColumnWidth = 31
Rows("1:1").RowHeight = H
End Sub
Sub Tester()
MsgBox "Vous avez cliquez sur le bouton test"
End Sub