Object variable not set, using UnoService

I’ve looked at other questions with “Object variable not set” and not found an answer.

My code:

Sub TestDaysBefore
Dim settlement As Date
Dim maturity As Date
Dim days As Integer

settlement = InputBox("Enter the settlement date (YYYY-MM-DD):", "Settlement Date")
    If Not IsDate(settlement) Then
        MsgBox "Invalid settlement date entered.", 16, "Error"
        Exit Sub
    End If
 maturity = InputBox("Enter the maturity date (YYYY-MM-DD):", "Maturity Date")
    If Not IsDate(maturity) Then
        MsgBox "Invalid maturity date entered.", 16, "Error"
        Exit Sub
    End If
    
    Dim oService as Object
   oService = CreateUnoService("com.sun.star.sheet.addin.Analysis")
   days = oService.getCoupdaybs(settlement, maturity,2) 'THIS LINE GENERATES THE ERROR
   MsgBox(days)
   
End Sub

I get the error “BASIC runtime error. Object variable not set”.

Would appreciate help.

See tdf#148646. Where is the first XPropertySet argument, that the function expects? And the bug explains, that the argument may be current document; and you may also use alternative call via com.sun.star.sheet.FunctionAccess, not requiring that extra argument.

Thanks for this info, but I’m not smart enough that it helps me fix the code. Can you please suggest amendments to the code that will make it work?

   oService = CreateUnoService("com.sun.star.sheet.FunctionAccess")
   days = oService.callFunction("com.sun.star.sheet.addin.Analysis.getCoupdaybs", array(CDbl(settlement), CDbl(maturity), 2))
1 Like

Thank you, that works (though I don’t know why!)

Maybe the LibreOfficeHelp page should be amended to provide an explanation, since their suggested method seems to throw this error?

See: Using Calc Functions in Macros

Particuarly the section entitled Calling Add-In Calc Functions in BASIC

It seems to me, that the bug report I mentioned was exactly about that?

Yes, I’m sure you’re right. I just meant that whoever maintains the help page might mention in this section that the suggested syntax may for add-in functions may not work

mikekaganski
January 23

ocorlett:

Maybe the LibreOfficeHelp page should be amended to provide an explanation

It seems to me, that the bug report I mentioned was exactly about that?


Visit Topic or reply to this email to respond.

To unsubscribe from these emails, click here.