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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
| Sub LancementProcedure()
Dim X As Object
Dim NomMonthView As String
NomMonthView = "MonthView1"
'Lance la procédure de création du userform et du contrôle MonthView
Set X = UserForm_Et_MonthView_Dynamique(NomMonthView)
'Affichage userform
X.Show
'Suppression du userform après la fermeture
ThisWorkbook.VBProject.VBComponents.Remove Usf
Set Usf = Nothing
End Sub
Function UserForm_Et_MonthView_Dynamique(NomObjet As String) As Object
Dim Obj As Object
Dim j As Integer
'Création UserForm
Set Usf = ThisWorkbook.VBProject.VBComponents.Add(3)
With Usf
.Properties("Caption") = "Mon calendrier"
.Properties("Width") = 135
.Properties("Height") = 140
End With
'Création du contrôle MonthView
Set Obj = Usf.Designer.Controls.Add("MSComCtl2.MonthView.2")
With Obj
.Left = 0: .Top = 0: .Width = 150: .Height = 140
.Name = NomObjet
.ForeColor = &HC000C0
.TitleBackColor = &HC000C0
End With
'Ajout de la procédure évènementielle DateClick du contrôle MonthView
With Usf.CodeModule
j = .CountOfLines
.insertlines j + 1, "Sub " & NomObjet & "_DateClick(ByVal DateClicked As Date)"
'Insère la date dans la cellule active
.insertlines j + 2, " ActiveCell = DateClicked"
'Option pour refermer l'userform après l'insertion de la date.
.insertlines j + 3, " Unload Me"
.insertlines j + 4, "End Sub"
End With
VBA.UserForms.Add (Usf.Name)
Set UserForm_Et_MonthView_Dynamique = UserForms(UserForms.Count - 1)
End Function |
Partager