Question : Looking for NETWORKDAYS VBA Equivalent without Analysis ToolPack or Analysis ToolPack VBA

I have a user environment where Excel 2003 is wrapped and thus unable to perform any reinstall-uninstall function without going through a regional IT approval.

I have recently developed a VBA routine to perform calculation, but needs the NETWORKDAYS functionality provided by the add-in. I have looked up and down but most suggestions will center around putting:

With .AddIns("Analysis Toolpak")
         .Installed = False
         .Installed = True

which didn't work for me. My question is really, is there a complete function in VBA that is add-in free and replaces NETWORKDAYS 100%? I have a holiday table maintained in Access so it is unlikely the holiday dates can be hardcoded . I can export the access holiday table in to a text file but the VB function must be able to read the text file.

Any idea?

Answer : Looking for NETWORKDAYS VBA Equivalent without Analysis ToolPack or Analysis ToolPack VBA

Here you go.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
Function Networkdaysvba(startDate As Date, endDate As Date, Optional holidays As Variant) As Integer
    Dim i As Integer
    Dim tmp As Integer
    Dim dt As Date, dtStart As Date
    
    tmp = ((endDate - startDate + 1) \ 7) * 5 ' entire work weeks
    dtStart = startDate + (tmp * 7 / 5) ' move to last week
    For dt = dtStart To endDate
        If Weekday(dt, vbMonday) <= 5 Then tmp = tmp + 1 ' add work days in the last week
    Next
    
    If IsArray(holidays) Then
        For Each h In holidays
            ' if any holiday falls in the range, remove it
            If Weekday(h, vbMonday) <= 5 And _
                startDate <= h And endDate >= h Then
                tmp = tmp - 1
            End If
        Next
    End If
    Networkdaysvba = tmp
End Function
Random Solutions  
 
programming4us programming4us