View Single Post
 
Old 10-20-2021, 07:40 AM
whatstheword whatstheword is offline Windows 10 Office 2016
Novice
 
Join Date: Oct 2021
Posts: 2
whatstheword is on a distinguished road
Default Calculating number of work dates between two days

Hello there,


I'm trying to create a macro for a Microsoft Word document that returns the number of the business days (i.e. no Sunday and Saturday) between an inputted start date and the current date.


I tried to search for/write code that excludes weekends and insert it into the following macro, but have been unsuccessful thus far.


Your help would be much appreciated!



Sub CalculateDateDifference()
Dim xStartDate As Date
Dim xEndDate As Date
Dim xDay As Long
On Error Resume Next
xStartDate = InputBox("Enter the start date", "Start Date", "")
xEndDate = Date
If (InStr(1, Str(xStartDate), ":") > 0) Or (InStr(1, Str(xEndDate), ":") > 0) Then
MsgBox "please input current date", vbInformation, "Date Calculation"
Exit Sub
End If
xDay = DateDiff("d", xStartDate, xEndDate)
MsgBox "There are " & xDay & " days from " & xStartDate & " to " & xEndDate & vbCrLf, vbInformation, "Date Calculation"
End Sub
Reply With Quote