Page 1 of 1

[Solved] [Calc] "property or method not found" when printing

PostPosted: Sat Feb 13, 2021 9:29 am
by F. Delente
Hello,

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, it switches to that second sheet to print it, then comes back to the initial sheet I was on.

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

Code: Select all   Expand viewCollapse view
'   Sheets("facture").PrintOut

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

sPrefix="print_listener_"
sService="com.sun.star.view.XPrintJobListener"
If NOT oDoc.sheets().hasByName("facture") Then
  MsgBox "Le document n'a pas de page nommée 'facture'"
Else
  Dim oSheets
  oSheets = oDoc.Sheets
  Dim currentSheet
  currentSheet = oDoc.getcurrentcontroller.activesheet

  oDoc.currentController.setActiveSheet(oSheets.getByName("facture"))
  oPrintListener=CreateUnoListener(sPrefix,sService)
  oDoc.addPrintJobListener(oPrintListener)
  ' oPrintJobListnerDoc=oDoc
  oDoc.Print(Array())

  wait 600

  oDoc.currentController.setActiveSheet(currentSheet)
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", OpenOffice 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!

Re: [Calc] "property or method not found" when printing

PostPosted: Sat Feb 13, 2021 12:10 pm
by Villeroy
Increase the milliseconds to wait.

Re: [Calc] "property or method not found" when printing

PostPosted: Sat Feb 13, 2021 12:59 pm
by F. Delente
Hello,

By how much? I tried with 'wait 6000' and I still have the error.

EDIT: with 'wait 12000' the error is still there.

Re: [Calc] "property or method not found" when printing

PostPosted: Sat Feb 13, 2021 1:37 pm
by Villeroy
I was shooting into the dark. No further ideas from my side.

Re: [Calc] "property or method not found" when printing

PostPosted: Sat Feb 13, 2021 2:33 pm
by F. Delente
Thanks for your input. I also posted on stack overflow and somebody there told me that for the printListener interface two other methods had to be implemented, so now my problem is solved.

Re: [Solved][Calc] "property or method not found" when print

PostPosted: Sat Feb 13, 2021 2:35 pm
by Villeroy
You should have posted all of the code. May be I would have catched this.

Re: [Solved][Calc] "property or method not found" when print

PostPosted: Sat Feb 13, 2021 2:37 pm
by F. Delente
OK sorry; I'll do that next time I'll have a problem :^)

Re: [Solved] [Calc] "property or method not found" when prin

PostPosted: Sun Feb 14, 2021 12:49 am
by Mountaineer
Link to the answer at stackoverflow:
https://stackoverflow.com/questions/661 ... rchResults

From JohnSUNs answer (abbreviated)
Creating an event listener assumes that there are two more procedures somewhere in your code - print_listener_printJobEvent (evt) and print_listener_disposing ()
...