View Full Version : Solved: using a worksheet function in vba

06-20-2008, 09:23 PM

I am trying to get the number of week days between two date.
it seems I am using application.networkdays wrongly.

can someone tell me what's wrong with this tiny bit of code please?

Call Constants

Dim Start_Date As Variant, End_Date As Variant
Dim Total_Days As Double

Dim i As Integer

Set Start_Date = wsRC_Simple.Cells(19, 1)
Set End_Date = wsRC_Simple.Cells(19, 2)

'Set objexcel = CreateObject("Excel.Application")

Total_Days = Application.networkdays(Start_Date, End_Date)

For i = 1 To Total_Days
wsOutput.Cells(i, 1) = i

06-20-2008, 09:54 PM
ok, I'll auto reply to myself. maybe it will help some beginners too someday ;)

networkdays is an Analysis Toolpack Function.
you need to select the ATP in Excel / Addins
THEN: make a REFERENCE in your vba code to ATPBAEN.xls (go to "Tools/ References")

after that it is possible to call the function as a normal excel function

06-21-2008, 12:44 AM
You can also use Application.Run

Total_days = Application.Run("'atpvbaen.xla'!Networkdays", Start_date, End_date)