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
| Sub PutControlErrorsBtn()
Dim Obj As OLEObject
Dim Sh As Worksheet
Dim Code As String, NomBouton As String
NomBouton = "ControlErrorsBtn"
Set Sh = ThisWorkbook.Sheets(1)
On Error Resume Next
Set Obj = Sh.OLEObjects(NomBouton)
On Error Resume Next
'On vérifie si notre bouton existe déjà
If Obj Is Nothing Then
Set Obj = Sh.OLEObjects.Add(ClassType:="Forms.CommandButton.1", Link:=False, DisplayAsIcon:=False, Left:=0, Top:=0, Width:=180, Height:=24)
Obj.Name = NomBouton
Obj.Object.Caption = "Recherche des erreurs d'extraction"
Code = "Private Sub " & NomBouton & "_Click()" & vbCrLf
Code = Code & " Constat2ExtractErrors" & vbCrLf
Code = Code & "End Sub"
With ThisWorkbook.VBProject.VBComponents(Sh.CodeName).CodeModule
.insertlines .CountOfLines + 1, Code
End With
Set Obj = Nothing
End If
Set Sh = Nothing
End Sub |
Partager