MartinBecks
New Member
- Joined
- Jul 7, 2014
- Messages
- 12
I have 4 sheets in my workbook. Only 1 sheet named "Data Sheet" do people enter information and depending on the numbers of rows filled out it prints accordingly. I'm ok there. My issue is in printing the other sheets which has instructions and reference material. When I try printing another tab the message box appears. How do I modify the code so the print button only works for the "Data Sheet"?
I know all I need is a little fix but I didn't originate this code, a colleague did. In advance thank you.
I have the following code in ThisWorkbook
and the following code in Module 1
I know all I need is a little fix but I didn't originate this code, a colleague did. In advance thank you.
I have the following code in ThisWorkbook
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)If PrtOK Then
Cancel = False
Else
MsgBox "Please use the embedded print button"
Cancel = True
End If
End Sub
and the following code in Module 1
Code:
Public PrtOK As BooleanSub Button41_Click()
PrtOK = True
Dim LastRow As Long
LastRow = Range("L" & Rows.Count).End(xlUp).Row
Set HeaderRange = Range("$A$1:$Q$16")
Set BodyRange = Range("$A$17:$Q$" & LastRow)
Set FooterRange = Range("$A$216:$Q$220")
Set UnionRange = Application.Union(HeaderRange, BodyRange)
With ActiveSheet.PageSetup
.PrintArea = UnionRange.Address
End With
'show print dialog
Application.Dialogs(xlDialogPrint).Show
PrtOK = False
End Sub