Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 07-22-2018, 02:09 PM
gmaxey gmaxey is offline Count number of days Windows 7 32bit Count number of days Office 2016
Expert
 
Join Date: May 2010
Location: Brasstown, NC
Posts: 1,617
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Count number of days Inserting a formula to count 30 days before and after a date in WORD table bjh894 Word 9 05-18-2020 11:14 AM
Count number of days count a number of cells based on the beginning of a order number Kubi Excel 2 08-06-2017 08:54 PM
Locking number of days in a project Mdon1 Project 0 06-10-2017 02:40 AM
Count number of days Assigning number of days MarcF Project 3 07-16-2016 10:44 AM
Count number of days How to count even exact date 90 days redza Excel 1 09-17-2013 03:36 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:52 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft