preventing printing in Excel

M

misscrf

Interesting discovery. I found this code on an old post:

Private Sub Workbook_BeforePrint(cancel As Boolean)
cancel = True
MsgBox "This page cannot be printed."
End Sub

I put this in, and then protected the worksheet, with autofilter on,
allowing sort and autofilter. The message comes up like it should.
The catch is that if you go to Tools | Macro | VB Editor - you can
delete the code! The code is not protected from being deleted in a
protected workbook!

Wow that is nuts. Just thought I would put this out there.
 
P

Peo Sjoblom

You can protect it in the VBE, press Alt + F11, find the workbook
in the left project pane, you can right click and select VBAProject
Properties, there you can protect it

Regards,

Peo Sjoblom
 
D

Dave Peterson

Excel supports lots of levels of protection.

You can protect the workbook with a password to open (file|saveAs|general
options)

You can protect the workbook so that sheets can't be
renamed/moved/deleted/inserted (tools|Protection|protect workbook)

You can protect the locked cells on a worksheet (tools|Protection|protect sheet)

And you can protect the workbook's project.
Inside the VBE
tools|VBAProject Properties|Protection tab.

(Each of these protections can be broken--some easier than the others.)

You want that VBAProject protection.
 
Top