I’m trying to call the NETWORKDAYS function within a macro using the UNO function access service. It works fine when I specify the to and from dates. However, I can’t get the optional Holiday list to work. Everything I try results in an Illegal Argument Exception. How should this be done?
If you are looking for the holidays themselves to be located within the macro, I don’t believe this is possible. The function is looking for a cell range for the list of holidays.
The following works with the holidays listed on a sheet:
function MYNETWORKDAYS(X,Y) 'Where X = Start Date & Y = End Date'
dim oFunction as variant
dim oSheet as object
dim oRange as object
dim result as double
oFunction = createUnoService("com.sun.star.sheet.FunctionAccess")
oSheet = ThisComponent.Sheets.getByName("SHEET-NAME-CONTAINING-HOLIDAY-DATES")
dim aArgument(2) as variant
aArgument(0)=X
aArgument(1)=Y
oRange = oSheet.getCellRangeByName( "G3:G6" ) 'Cell range of holiday dates'
aArgument(2)=oRange
result = oFunction.callFunction( "NETWORKDAYS", aArgument() )
MYNETWORKDAYS = result
end Function
Great, this works!
I had tried both adding an array of dates to the arguments and a range but had improperly extended the range definition with some unneeded and erroneous range address stuff.
Thanks,
Hartley
Cincinnati, Ohio