Forum Discussion
byloom
Sep 22, 2022Copper Contributor
Personalize Output Print based on the las row with data and Printer Setting
Dear All, i have a woorkbook with N sheets i have one file where i can select the sheet to print and use a button to print the sheet i select, i can select also multiples sheets. i am using this...
HansVogelaar
Sep 22, 2022MVP
byloom
Sep 22, 2022Copper Contributor
ok thank you so much, and if i want to print a range from like from A1 to M50 how i can set it please? appreciate
- HansVogelaarSep 22, 2022MVP
Somewhere between the lines
With ActiveSheet.PageSetup
and
End With
insert
' Set print area .PrintArea = "$A$1:$M$50"
- byloomSep 23, 2022Copper Contributorthank you so much, is not working i sent you a dm appreciate
- HansVogelaarSep 23, 2022MVP
You want to apply the print settings to each selected sheet, not to the active sheet (which is the Control Sheet):
Sub Print_Sheets() Dim i As Long, c As Long Dim SheetArray() As String Application.PrintCommunication = False With ActiveSheet.ListBoxSh For i = 0 To .ListCount - 1 If .Selected(i) Then ReDim Preserve SheetArray(c) SheetArray(c) = .List(i) With Sheets(.List(i)).PageSetup ' Set print area .PrintArea = "$A$1:$M$50" ' Set the header .CenterHeader = "&A" ' Set the margins .LeftMargin = Application.InchesToPoints(0.25) .RightMargin = Application.InchesToPoints(0.25) .TopMargin = Application.InchesToPoints(0.75) .BottomMargin = Application.InchesToPoints(0.75) .HeaderMargin = Application.InchesToPoints(0.3) .FooterMargin = Application.InchesToPoints(0.3) ' Fit to one page wide .Zoom = False .FitToPagesWide = 1 .FitToPagesTall = 0 .Orientation = xlLandscape End With c = c + 1 End If Next i End With Application.PrintCommunication = True Application.Dialogs(xlDialogPrinterSetup).Show Sheets(SheetArray).PrintPreview 'If you'd like to print out 'Sheets(SheetArray()).PrintOut End Sub