How to apply a paper tray to ALL page styles?

For any given pre existing document (of which there are literally hundreds of thousands) I need to create a macro that will print the first page on paper from Tray 2 and all subsequent pages from Tray 1. Is there a simple way of doing this?

So far the only way I can find is to change the paper tray settings in the various page styles. This approach is no good however because for any given document I do not know which page styles will be applied within.

I’d say: print the document in two print jobs, first page from tray 2 and the rest from tray 1. Assuming that the used page styles never set a value for the tray to use that should work. As this is very obvious, there’s probably a snag.

Alternatively, you’d have to figure out how to address all page styles used in a document and be sure that the first page of any document always has a page style not used anywhere else in that document.

Trying your first suggestion and having two print jobs is certainly an option. The problem I have is that I start recording a macro, set the paper to tray 2 and then print page 1, set it to paper tray 1 and print pages 2 onwards. I then stop the macro and save it. During the recording process the printer spits out the pages on the correct paper.

When I then run that macro absolutely nothing happens. The recorded macro looks like this:

sub MainPrint
rem ----------------------------------------------------------------------
rem define variables
dim document   as object
dim dispatcher as object
rem ----------------------------------------------------------------------
rem get access to the document
document   = ThisComponent.CurrentController.Frame
dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:Print", "", 0, Array())

rem ----------------------------------------------------------------------
rem dispatcher.executeDispatch(document, ".uno:Print", "", 0, Array())


end sub

It seems to me that the macro is very light on detail. When I record it, I go into ‘Printer Settings’ and then ‘Properties’ and have to choose the paper tray from within there (the same place you would select the tray if you were viewing the printer properties from the Windows control panel). I simply cannot see anywhere else to choose the paper tray other than in the “Page Style” modify options.

thanks again for your help

It’s really better to dive into the macro language and forget about recording macros. Begin right here.

In the Options for LO it states for macro recording “Enable macro recording (limited)”. Recording a macro does not always create the desired result.

I recorded a macro to print and it created a similar result as the macro you posted. The reason it does not print when run is that strangely the line to execute the print is preceded by REM.

rem dispatcher.executeDispatch(document, ".uno:Print", "", 0, Array())

If you remove the REM then it does print but brings up the print dialog box first. It seems that the macro recorder does not record the selections made in the print dialog - one of the limitations I guess.

As @anon87010807 said you will need to look into programming this in Basic. The example he pointed to does show selection of the Tray but does this by changing the Page Format.