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
' 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
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!