PDA

View Full Version : Auto print last filled page



dzogchen
06-27-2011, 12:23 PM
Hello all,

I'm trying to develop a code that auto prints the last filled page in a sheet.

The code that I develop so far is the following:

Sub HowManyPagesBreaks()

Dim iHpBreaks, iTotPages , x , z As Integer

x = ActiveSheet.HPageBreaks.Count + 1


'Code


z = ActiveSheet.HPageBreaks.Count + 1

If z > x Then PrintOut from:=x, to:=x
End Sub

This does what I want, but when the Code have almost 2000 lines it becames very very slow to run the macro, I think that is because the page preview.

Anyone have a better idea that could help me?

Regards

Trebor76
06-27-2011, 07:03 PM
Hi dzogchen,

Try the following which uses Excel's Version 4.0 Macro Language 'ExecuteExcel4Macro("GET.DOCUMENT(50)")' to print the last page (I think that's what you're asking for):


Sub LastPrintPage()
If Application.ExecuteExcel4Macro("GET.DOCUMENT(50)") > 0 Then
ActiveSheet.PrintOut _
From:=Application.ExecuteExcel4Macro("GET.DOCUMENT(50)"), _
To:=Application.ExecuteExcel4Macro("GET.DOCUMENT(50)")
End If
End Sub

Regards,

Robert

dzogchen
06-28-2011, 11:37 AM
Hello Robert,

Thank you for your reply!

Your code is printing the last page every time I run the macro.

The ideia is to print the last page when all the cell are <> 0 only once. If you try to run my code you will understand want I want. Change the īCode for the following so you can see it run:

For n = 1 To 25
ActiveCell.Offset(1, 0).Activate
ActiveCell.Value = "bbb"
Next n

Regards

Trebor76
06-28-2011, 04:17 PM
If you try to run my code you will understand want I want.

No it doesn't I'm afraid :confused:

I'm sure (hopefully) someone on the forum will be able to help.

dzogchen
06-29-2011, 10:49 AM
Sorry for not beeing explicit.

I'm trying to develop a macro to make an event registry in excel. Each printable page will have 22 lines, as you can see in the following picture:

http://www.megagaleria.com/pictures/Pic_4719_29.jpg

(you can see how many times I have run the macro by counting the SC-number)


What I'm looking for is a command that will print the last page when all the 22 lines are written so we can have the registers in paper. No need to print every time when we run the macro, just need to print only when the page is complete. Dont forget the IFM is in Portugal, we need to save on paper. :cool:

I hope that helps

Regards