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

Keyboard macros or custom scripts

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

Postby F. Delente » Sat Feb 13, 2021 9:29 am

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!
Last edited by F. Delente on Sat Feb 13, 2021 2:33 pm, edited 1 time in total.
LibreOffice 7.0.4.2 on Linux 5.10 (Fedora 33)
F. Delente
 
Posts: 4
Joined: Fri Feb 12, 2021 9:45 pm

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

Postby Villeroy » Sat Feb 13, 2021 12:10 pm

Increase the milliseconds to wait.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
 
Posts: 30155
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby F. Delente » Sat Feb 13, 2021 12:59 pm

Hello,

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

EDIT: with 'wait 12000' the error is still there.
LibreOffice 7.0.4.2 on Linux 5.10 (Fedora 33)
F. Delente
 
Posts: 4
Joined: Fri Feb 12, 2021 9:45 pm

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

Postby Villeroy » Sat Feb 13, 2021 1:37 pm

I was shooting into the dark. No further ideas from my side.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
 
Posts: 30155
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby F. Delente » Sat Feb 13, 2021 2:33 pm

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.
LibreOffice 7.0.4.2 on Linux 5.10 (Fedora 33)
F. Delente
 
Posts: 4
Joined: Fri Feb 12, 2021 9:45 pm

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

Postby Villeroy » Sat Feb 13, 2021 2:35 pm

You should have posted all of the code. May be I would have catched this.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
Villeroy
Volunteer
 
Posts: 30155
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby F. Delente » Sat Feb 13, 2021 2:37 pm

OK sorry; I'll do that next time I'll have a problem :^)
LibreOffice 7.0.4.2 on Linux 5.10 (Fedora 33)
F. Delente
 
Posts: 4
Joined: Fri Feb 12, 2021 9:45 pm

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

Postby Mountaineer » Sun Feb 14, 2021 12:49 am

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 ()
...
OpenOffice 3.1 on Windows Vista
Mountaineer
 
Posts: 93
Joined: Sun Sep 06, 2020 8:27 am


Return to OpenOffice Basic, Python, BeanShell, JavaScript

Who is online

Users browsing this forum: No registered users and 1 guest