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
| Sub MiseDuCode(ByRef NomDuLabel As String)
'1 voir si le code n'est pas déja placé
If Not IsCodeExistant(NomDuLabel & "_Click") Then
'Mise en place du code bouton appuyer
With ActiveWorkbook.VBProject.VBComponents("ufMonAnnuaire").CodeModule
'.insertlines ., stmoncode
' Call .CreateEventProc("Click", NomDuLabel)
' x = .ProcStartLine(NomDuLabel & "_Click", vbext_pk_Proc)
'stMonCode = "msgbox " & Chr(34) & " coucou" & Chr(34)
x = .CountOfLines
stMonCode = "private sub " & NomDuLabel & "_Click()" & vbCr & "msgbox " & Chr(34) & " coucou" & Chr(34) & vbCr & "end sub"
.InsertLines x + 2, stMonCode
End With
End If
End Sub
Function IsCodeExistant(ByRef stNomCode As String) As Boolean
'fonction qui renvoie vrai si le code Stnomcode se trouve bien dans la feuille (ou module ou classe) nomfeuille
Dim iFin As Byte
Dim i As Byte
With ThisWorkbook.VBProject.VBComponents("ufMonAnnuaire")
'affiche le code
On Error Resume Next
IsCodeExistant = (.CodeModule.ProcStartLine(stNomCode, 0) > 0)
End With
End Function |
Partager