Help with macro button to "direct" print

Hello.

I’m trying to make a macro to directly print a portion of a sheet when I click on it. The basic code below sort of works:

Dim Document As object

Dim Dispatcher As Object

Document = ThisComponent.CurrentController.Frame

Dispatcher = createUNOService(“com.sun.star.frame.DispatchHelper”)

Dispatcher.executeDispatch(Document,".uno:Print", “”, 0, Array())

The only problem is that whenever I press a button to call this macro, the print procedure starts as expected but also still goes through the “Print preview” menu every time. I’d like to skip that part, and go straight to a print without any further interaction/confirmation/user input required.

So, how can I adjust the code so that it will skip that part, and print without further confirmation?

…who wants paper?

I actually did find that post, and tried to adjust it to my needs (print a physical paper, not a pdf) – no luck.

Sorry, I can’t help. As @Villeroy noted, printing to a PDF printer and a real printer is different. To give a working example of a macro, it needs to be debugged, tested. And this is exactly what I cannot do - for many years I have not had a printer and, hopefully, I will never need it again in the third millennium.

In the macro replace Print with PrintDefault.

I printed according to the last defined parameters.

For guarantee, it is better to define range…

sub Printed
dim document   as object
dim dispatcher as object
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")
dim args1(0) as new com.sun.star.beans.PropertyValue
args1(0).Name = "ToPoint" : args1(0).Value = "$Plan1.$B$3:$H$45" '<==== RANGE
dispatcher.executeDispatch(document, ".uno:GoToCell", "", 0, args1())
dispatcher.executeDispatch(document, ".uno:DefinePrintArea", "", 0, Array())
dispatcher.executeDispatch(document, ".uno:PrintDefault", "", 0, Array())
end sub 'Printed
1 Like

… and if you want to have a toolbar button, you don’t need a macro for that at all? Just put the .uno:PrintDefault button (named “Print Directly” in English UI) to the toolbar in customization dialog?

1 Like

2 Likes

PrintDefault seems to have solved the problem when testing it at home (…without a physical printer lol), at least when saving as pdf. I’ll try the physical print tomorrow at work; hopefully schiavinatto/mikekaganski’s solutions will both work.