Call Sub using Print Range Variables

Clintster

New Member
Joined
May 30, 2012
Messages
7
I needed a sub that could be used for various range on various sheets. each sheet has different buttons to initiate a print dependant on parameters in the Action for the button sub. It took a few days and several headaches to figure it out. There may be other short cuts but this does work.

I was also able to change the page orientation and keep original rows and cols with the last two parameters in the sub call.


Sub PrintRnd1()
Dim PrtFirstRow, PrtFirstCol, PrtLastCol, PrtLastRow As Integer
Dim CountTeams As Integer
Dim MyPrintTitle As String
Call DeleteButton("AllDraw")
CountTeams = 2
Do While True
Range("E" & CountTeams & "").Select
If ActiveCell <> "" Then
CountTeams = CountTeams + 1
Else
Exit Do
End If
Loop
PrtFirstRow = 1
PrtFirstCol = 5
PrtLastCol = 9
PrtLastRow = CountTeams - 1
MyPrintTitle = "Round 1"
Call PrintSheet(PrtFirstRow, PrtFirstCol, PrtLastRow, PrtLastCol, MyPrintTitle, 0, 0)
End Sub
-------------------------
Sub PrintSheet(FRow, FCol, LRow, LCol, PrintTitle, KeepRowCol, PaperOrient)
Dim GoPrint, MyCopies, MyFRow, MyFCol As Integer
MyFRow = FRow
MyFCol = FCol

If KeepRowCol = 0 Then
For i = 1 To LCol
LRow = Range(Cells(600, i), Cells(600, i)).End(xlUp).Row
If LRow > FRow Then
FRow = LRow
FCol = i
End If
Next i
End If
If PaperOrient = 0 Then
MyOrient = xlPortrait
Else
MyOrient = xlLandscape
End If
LastCell = Range(Cells(LRow, LCol), Cells(LRow, LCol)).Address
FirstCell = Range(Cells(MyFRow, MyFCol), Cells(MyFRow, MyFCol)).Address
ActiveSheet.PageSetUp.PrintArea = FirstCell & ":" & LastCell
Range("" & FirstCell & ":" & LastCell & "").Select
Application.PrintCommunication = False
With ActiveSheet.PageSetUp
.LeftHeader = ""
.CenterHeader = PrintTitle
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = "" '"&""Agency FB,Bold""&8 5"
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.TopMargin = Application.InchesToPoints(0.75)
.BottomMargin = Application.InchesToPoints(0.5)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = True
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = True
.CenterVertically = False
.Orientation = MyOrient 'xlLandscape or xlPortrait
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False 'must be false when FitToPages variables are used
.FitToPagesWide = 1 ' else zoom = 100 and fittopages is removed or commented out
.FitToPagesTall = 1
.PrintErrors = xlPrintErrorsDisplayed
.OddAndEvenPagesHeaderFooter = False
.DifferentFirstPageHeaderFooter = False
.ScaleWithDocHeaderFooter = True
.AlignMarginsHeaderFooter = True
End With
Application.PrintCommunication = True
GoPrint = MsgBox("Are you ready to PRINT?", vbYesNo, "Print Now!")
If GoPrint = 6 Then
MyCopies = 0
MyCopies = InputBox("Number of Copies Needed." & vbCr & "Enter Number")
If MyCopies > 0 Then
ActiveWindow.SelectedSheets.PrintOut Copies:=MyCopies, Collate:=True, _
IgnorePrintAreas:=False
End If
End If
ActiveSheet.PageSetUp.PrintArea = ""
End Sub
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top