Function UserForm_Et_DataPicker_Dynamique(NomObjet As String) As Object
Dim Obj As Object
Dim j As Integer
Set Usf = ThisWorkbook.VBProject.VBComponents.Add(3)
With Usf
.Properties("Caption") = "Mon calendrier"
.Properties("Width") = 130
.Properties("Height") = 40
End With
Set Obj = Usf.Designer.Controls.Add("MSComCtl2.DTPicker.2")
With Obj
.Left = 0: .Top = 0: .Width = 130: .Height = 20
.Name = NomObjet
.CalendarBackColor = &HFF00FF
End With
With Usf.CodeModule
j = .CountOfLines
.insertlines j + 1, "Sub " & NomObjet & "_Change()"
.insertlines j + 2, " ActiveCell.Value = Format(DateSerial(Year(" _
& NomObjet & "), Month(" & NomObjet & "), Day(" _
& NomObjet & ")), " & Chr(34) & "dd mmmm yyyy" & Chr(34) & ")"
'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_DataPicker_Dynamique = UserForms(UserForms.Count - 1)
End Function