I am trying to create a public function in VBA so I may use the Excel Networkdays function in Access, I am a rookie in VBA. I have already mapped to the Excel Object Library in VBA by going to references. I can see the function but do not know how to link to it to be able to use it in a query.
My end goal is to be able create an Access query and use the networkdays function, for example, take a [QC date] and subtract the [repair_date] but deduct the weekend days.
NETWORKDAYS([REPAIR DATE],[QC DATE],OPTIONAL OR [HOLIDAYS])
I have made several attempts to copy others code from researching this and tried creating my own public function without success.
Here is what I have that I can access in a query but it does not calculate correctly, or I should say at all
Any help is much appreciated.
Public Function XLNETWORKDAYS(start_date As Date, end_date As Date, Optional Holidays As Date)
Dim objXL As Excel.Application
Set objXL = CreateObject("Excel.Application")
If IsMissing(Holidays) Then Holidays = False
XLNETWORKDAYS = objXL.WorksheetFunction.NetworkDays(start_date, end_date, Holidays)
Exit:
Exit Function
Thanks
My end goal is to be able create an Access query and use the networkdays function, for example, take a [QC date] and subtract the [repair_date] but deduct the weekend days.
NETWORKDAYS([REPAIR DATE],[QC DATE],OPTIONAL OR [HOLIDAYS])
I have made several attempts to copy others code from researching this and tried creating my own public function without success.
Here is what I have that I can access in a query but it does not calculate correctly, or I should say at all
Public Function XLNETWORKDAYS(start_date As Date, end_date As Date, Optional Holidays As Date)
Dim objXL As Excel.Application
Set objXL = CreateObject("Excel.Application")
If IsMissing(Holidays) Then Holidays = False
XLNETWORKDAYS = objXL.WorksheetFunction.NetworkDays(start_date, end_date, Holidays)
Exit:
Exit Function
Thanks