Page 1 of 1

Get which sheet is being printed

PostPosted: Mon Nov 19, 2018 7:31 pm
by mateus_bisognin
Hi,

I am trying to create a macro that backups data from a document to a csv file, but my main objective is to only backup data from the sheet that is being printed.

So, in my understanding, the way to do this is by attaching a macro to the "onprint" event, getting which sheet is being printed, then running some code.

On these 3 steps, I can't figure it out step 2: "get which sheet is being printed". I would like to, as the user goes through printing options on normal interface and sets which sheets and pages he wants to print, then set it to print, I want to grab these selected options as input to a macro.

I tried something like this attached to "onprint" event:
Code: Select all   Expand viewCollapse view
Sub Main(Event As Object)
...
End Sub

But then, I did not go anywhere.

Does anyone know if it is possible?

Hope I made it understantable.

Thank you in advance

Mateus

Re: Get which sheet is being printed

PostPosted: Thu Nov 29, 2018 3:50 pm
by VBandOoffice
Hi,
all print areas are items of an array. This snippet is not tested...
I hope this will help you.

oDoc=ThisComponent
oSheets=oDoc.Sheets

Dim aPrintingAreas(oDoc.Sheets.getCount-1)

For i=0 to oDoc.Sheets.getCount-1
aPrintingAreas(i)=oSheets(i).getPrintAreas()

' check if empty! Do what you want if not empty

Next

Regards,
VBandOoffice