View Single Post
 
Old 07-22-2018, 02:09 PM
gmaxey gmaxey is offline Windows 7 32bit Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,601
gmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nicegmaxey is just really nice
Default

Assuming leave start and leave end dates are entered in a datepicker type content control then something like this shoud work:

Code:
Sub Test()
Dim oCCS As ContentControl
Dim oCCE As ContentControl
Dim lngDays As Long
  Set oCCS = ActiveDocument.SelectContentControlsByTitle("Start").Item(1)
  Set oCCE = ActiveDocument.SelectContentControlsByTitle("End").Item(1)
  MsgBox fcnCalcDays(oCCS.Range, oCCE.Range)
lbl_Exit:
  Exit Sub
End Sub
Function fcnCalcDays(Date1 As Range, Date2 As Range) As Long
Dim lngDays As Long
Dim lngIndex As Long
Dim dTest As Date
  lngDays = 0
  dTest = Date1.Text
  For lngIndex = 1 To DateDiff("d", Date1.Text, Date2.Text)
    If Weekday(dTest, vbUseSystemDayOfWeek) <> 6 Then
      lngDays = lngDays + 1
    End If
    dTest = DateAdd("d", 1, dTest)
  Next
  fcnCalcDays = lngDays
lbl_Exit:
  Exit Function
End Function
__________________
Greg Maxey
Please visit my web site at http://www.gregmaxey.com/
Reply With Quote