OOBasic and Calc: "property or method not found" when printing a sheet


I’m trying to create a BASIC macro for Calc where I have data in a sheet and, when I execute my macro, some of the data is copied into another sheet and that second sheet is then printed.

After searching on the web, my code for printing is the following: (I don’t include the data-copying part because this part works)

 '   Sheets("facture").PrintOut

 Dim oDoc as Object
Dim sPrefix$  ' Prefix used to identify the print listener routines.
Dim sService$ ' Print listener service name

If NOT oDoc.sheets().hasByName("facture") Then
  MsgBox "Le document n'a pas de page nommée 'facture'"
  Dim oSheets
  oSheets = oDoc.Sheets
  Dim currentSheet
  currentSheet = oDoc.getcurrentcontroller.activesheet
  ' oPrintJobListnerDoc=oDoc
  wait 600

End If

This code doesn’t work: it pops up plenty of windows with “BASIC runtime error, Property or method not found: $(ARG1)” and no further info.

If I comment out the “wait 600” and “oDoc.currentController.setActiveSheet(currentSheet)” lines, the code works with no error and the sheet is printed, but it doesn’t go back to the sheet where I started the macro from (that’s the behavior I want).

If I only comment out the “wait 600”, LibreOffice stays on the sheet from which I started the macro, doesn’t switch to the one I want to print (visually at least) and prints an empty page.

Can anybody help me? Thanks!