Public Function NbOpenDay(dtDeb As Date, dtFin As Date) As Integer ' Calculer le nombre de jours ouvrables entre deux dates ' Utilise la fonction JourFérié(dtDate As Date) Dim dblDateDeb As Double Dim dblDateFin As Double Dim DateCourante As Date Dim resultat As Integer
If IsNull(dtDeb) Or IsNull(dtFin) _ Or IsEmpty(dtDeb) Or IsEmpty(dtFin) Then NbOpenDay = 0 Exit Function ElseIf Not IsDate(dtDeb) Or Not IsDate(dtFin) Then NbOpenDay = 0 Exit Function ElseIf dtDeb > dtFin Then Dim dhTemp As Date dhTemp = dtDeb dtDeb = dtFin dtFin = dhTemp End If
dblDateDeb = CDbl(dtDeb) dblDateFin = CDbl(dtFin)
Do Until dblDateDeb > dblDateFin DateCourante = CDate(dblDateDeb) If WeekDay(DateCourante) <> 1 And _ WeekDay(DateCourante) <> 7 And _ JourFérié(DateCourante) = False Then resultat = resultat + 1 End If dblDateDeb = dblDateDeb + 1 Loop
NbOpenDay = resultat
End Function |