I am trying to print a specific Calc sheet with a BASIC macro. The situation is that I am entering finance information on one sheet, then click a button to process the transaction, which (among other things) copies some data to a separate receipt sheet, and I want to print that receipt. All that I have seen on printing refers to a Print method for the entire document (and not a sheet, for example), with no way to specify the sheet. There are some print options, including which “page number”, but I believe this just refers to which pages to print from the current sheet. The Print method seems to be pretty good at printing the current sheet, so I would think the following would work:
Dim view As Object
view = oDoc.getCurrentController()
view.setActiveSheet(shtReceipt)
oDoc.Print(Array())
view.setActiveSheet(shtSource)
And it turns out that this does work, but only(!) when I am stepping through the code, and allow the receipt sheet to appear physically on the screen. But when I run the code full-speed, it always just prints the source sheet! It’s almost like Print will print what is visible on the screen, but the setActiveSheet goes by so quickly that the receipt isn’t visible (yet), and it just prints what is currently on the screen.
So what is the solution?