'-------------------------------------------------------------------
' Function: WorkDays()
' Purpose: Calculate the number of working days between two dates.
' Includes the start date and the end date; so, the number of days
' between 02/02/93 and 02/03/93 equals one.
' Note: This function does not account for holidays.
' To call the function, you can pass either a valid string or an
' actual date value:
' WorkDays("01/01/93", "12/31/96"), returns 1042.
' WorkDays("#03/05/93#, #04/06/93#), returns 22.
' Parameters: varBegDate - Beginning date.
' varEndDate - Ending date.
' Returns: The number of working days between two dates.
'-------------------------------------------------------------------
Function WorkDays(varBegDate As Variant, varEndDate As Variant) As Integer
On Error GoTo HandleErrors
Dim varWholeWeeks As Variant
Dim varDateCnt As Variant
Dim intEndDays As Integer
On Error GoTo HandleErrors
varBegDate = DateValue(varBegDate)
varEndDate = DateValue(varEndDate)
varWholeWeeks = DateDiff("w", varBegDate, varEndDate)
varDateCnt = DateAdd("ww", varWholeWeeks, varBegDate)
intEndDays = 0
Do While varDateCnt < varEndDate
If Format(varDateCnt, "ddd") <> "Sun" And _
Format(varDateCnt, "ddd") <> "Sat" Then
intEndDays = intEndDays + 1
End If
varDateCnt = DateAdd("d", 1, varDateCnt)
Loop
WorkDays = varWholeWeeks * 5 + intEndDays
ExitHere:
Exit Function
HandleErrors:
Select Case Err.Number
Case Else
MsgBox "Error: " & Err.Description & " (" & Err.Number & ")"
Resume ExitHere
End Select
End Function
'------------------------------------------------------------------