How to access "Analysis AddIn" functions for basic Macros in Calc

I want to use the DAYSINMONTH function in my Macro to get the days in the current month. I tried calling it but it says the subroutine isn’t found, so I assume as per the documentation linked that it requires the “Analysis AddIn”, but I can’t find any instructions anywhere on how to install that.

Anyone know how to achieve this seemingly basic feat?

Why use Calc functions when there are native tools in Basic?

Function DaysInMonth(ByVal d As Date) As Long
  If Month(d)=12 Then
    DaysInMonth=31
  Else  
    DaysInMonth = Day(DateSerial(Year(d), Month(d) + 1, 1) - 1)
  End If  
End Function
1 Like

Hello,

since there is a DAYSINMONTH as a spreadsheet function, you can get access to this function the usual way using CreateUNOService("com.sun.star.sheet.FunctionAccess"):

Function MyFunction(iDate As Long) As Variant

  Dim oFA      As Object
  Dim Array(0) As Variant

  Array(0) = iDate

  oFA = CreateUNOService("com.sun.star.sheet.FunctionAccess")
  MyFunction = oFA.callFunction("DAYSINMONTH",Array())

End Function

Notes

  • Did not check whether there is a Basic runtime function.
  • Did not check when DAYSINMONTH was introduced to LibreOffice Calc