Private Sub Workbook_Open()
Dim tablo, Limite As Integer, Alerte As Integer, Chaine As String
Limite = 90 ' Définit la limite qui déclenche l'alerte, ici 90 jours
Alerte = 30 ' Définit la limite qui déclenche l'alerte supplémentaire si <30 jours
tablo = Sheets("CDD").Range("A2").CurrentRegion
Chaine = ""
For i = 1 To UBound(tablo)
If tablo(i, 6) <= Limite And tablo(i, 6) > Alerte Then
Chaine = Chaine & tablo(i, 2) & vbTab & " CDD expire dans " & tablo(i, 6) & " jours." & Chr(10)
End If
If tablo(i, 6) <= Limite And tablo(i, 6) <= Alerte Then
Chaine = Chaine & tablo(i, 2) & vbTab & " CDD expire dans " & tablo(i, 6) & " jours." & vbTab & "Attention, moins d'un mois" & Chr(10)
End If
If tablo(i, 6) = "CDD échu" Then
Chaine = Chaine & tablo(i, 2) & vbTab & " CDD échu " & Chr(10)
End If
Next i
'M = MsgBox(Chaine, , "CDD expirant dans moins de " & Limite & " jours.")
nom = "liste des CDD expirant dans moins de " & Limite & " jours.txt"
Fichier = Environ("userprofile") & "\Desktop\" & nom
x = FreeFile: Open Fichier For Output As #x: Print #x, Replace(Chaine, Chr(10), vbCrLf): Close #x
CreateObject("Shell.Application").Namespace(0).ParseName(Fichier).InvokeVerb ("Print")
Application.Wait (Now + TimeValue("0:00:03"))
'kill fichier'si tu ne veux pas le garder
End Sub