I have a template that should only be used if it is for a certain ship to that ends up in a specific cell in t he workbook. I want to keep them from printing the file if the ship to does not match what I need it to match.
I have the below code in the ThisWorkbook module.
I am using Excel 2016 but most of the users of this template will be running 2013. I have viewed many posts on how to do the Before Print event but I can't seem to get it to work for me. I do File --> Print and the code never runs. I do quick print and the code never runs.
Is it just because of the version of Excel I'm using? If yes is there anyway to keep them from printing it?
I'd even take something that would pop up a message box if the value in that cell isn't Canada. THe problem is that the template is tied to another file and a vlookup is dependent on them putting a valid sales order number in another cell so the VLOOKUP returns the actual Ship to. So if the value was #N/A I wouldn't want the message box to pop up.
Any help is much appreciated!!!
I have the below code in the ThisWorkbook module.
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim Data_Book As String
Dim ShipTo As String
Data_Book = ThisWorkbook.Name
ShipTo = Workbooks(Data_Book).Sheets("Sheet1").Range("A12")
If ShipTo <> "Canada" Then
Cancel = True
MsgBox ("This template is ONLY for Canada orders. Please close this workbook and open the Non-Canada template."), vbOKOnly
End If
End Sub
I am using Excel 2016 but most of the users of this template will be running 2013. I have viewed many posts on how to do the Before Print event but I can't seem to get it to work for me. I do File --> Print and the code never runs. I do quick print and the code never runs.
Is it just because of the version of Excel I'm using? If yes is there anyway to keep them from printing it?
I'd even take something that would pop up a message box if the value in that cell isn't Canada. THe problem is that the template is tied to another file and a vlookup is dependent on them putting a valid sales order number in another cell so the VLOOKUP returns the actual Ship to. So if the value was #N/A I wouldn't want the message box to pop up.
Any help is much appreciated!!!