'callback pour la classe calendrier
Public Function DateValueX(Optional obj As Object = Nothing, Optional langue As Long = -1)
Dim forme
With Calendrier
If obj Is Nothing Then
.StartUpPosition = 1
Else
.StartUpPosition = 0
End If
.DateSepar = Switch(langue = 0, "/", langue = 2, "-", langue = 1, "/", langue = -1 Or langue > 2, Application.International(xlDateSeparator))
.DateOrder = Switch(langue > -1, langue, langue = -1 Or langue > 2, Application.International(xlDateOrder))
If Not obj Is Nothing Then
Set .obj = obj
Select Case TypeName(obj)
Case "Range"
If IsDate(obj.Value) Then .dat = CDate(obj.Value) Else dat = Date
oldate = obj.Value
Case "TextBox"
If IsDate(obj.Text) Then .dat = CDate(obj.Text) Else dat = Date
oldate = obj.Text
Case "Label", "CommandButton"
If IsDate(obj.Caption) Then .dat = CDate(obj.Caption) Else dat = Date
oldate = obj.Caption
Case "Shape", "DrawingObject"
If IsDate(ActiveSheet.DrawingObjects(obj.Name).Text) Then .dat = CDate(ActiveSheet.DrawingObjects(obj.Name).Text) Else dat = Date
oldate = ActiveSheet.DrawingObjects(obj.Name).Text
Case Else: dat = Date 'au cas ou l'appelant n'est pas identifié
End Select
Else
dat = Date
End If
If obj Is Nothing Then Me.StartUpPosition = 1
Show
Select Case .DateOrder
Case 0, 2: forme = "yyyy" & .DateSepar & "mm" & .DateSepar & "dd"
Case 1: forme = "DD" & .DateSepar & "mm" & .DateSepar & "yyyy"
End Select
If .Tag <> "no" Then
Select Case TypeName(obj)
Case "Range"
DateValueX = dat
If langue > -1 Then obj.NumberFormat = forme
Case "TextBox", "Label", "CommandButton", "Shape"
DateValueX = Format(dat, forme)
Case Else: DateValueX = dat
End Select
Else
DateValueX = oldate 'si on ferme par la croix on remet ce qu'il y avait
End If
Unload Calendrier
End With
End Function