Stop a Worksheet from Printing

IanSYP

New Member
Joined
May 19, 2005
Messages
9
Good Morning

I need to stop a user from being able to print a worksheet

I know i need to put a bit of code in the sheet but have no idea what it should look like. Somebody has mentioned a before Print Events??? but unsure on this

Any ideas

Thank you very much
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
Ian

Perhaps it's the BeforePrint workbook event you want.

To access that right click the Excel icon next to File and select view code.

That should open the VBA editor and display the workbook's class module.

Now select Workbook from the left dropdown and BeforePrint from the second.

You should now see this code stub.
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)

End Sub
To cancel printing just add Cancel = True.
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
     Cancel = True
End Sub
If it's a specific sheet you want to stop printing then you could use something like this.
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Cancel = ActiveSheet.Name = "Sheet1"
End Sub
 
Upvote 0
Good morning IanSYP

I need to stop a user from being able to print a worksheet

One user or any user? A worksheet or an entire workbook?

This code will prevent a workbook from being printed. It can be expanded on if need be :

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Cancel = True
MsgBox "Sorry - this workbook cannot be printed"
End Sub

This code needs copying into the ThisWorkbook module.

HTH

DominicB
 
Upvote 0
Thank You

Just a quick message of thanks as that has sorted the problem i have now and the next question i was going to ask
 
Upvote 0
Remember that there's nothing to stop anyone copying data to another workbook, and printing it from there!!
 
Upvote 0
Hi pcc

Remember that there's nothing to stop anyone copying data to another workbook, and printing it from there
... nor to stop anyone opening the file and choosing not to run macros and printing away to their hearts content. As we all know Excel is not a secure environment and any tricks that a spreadsheet developer can implement to stop users doing things they shouldn't can be circumvented by someone determind to wreak havoc in your system.

It's fine for preventing accidental destruction, but don't trust your secrets to Excel's security...

DominicB
 
Upvote 0
Hi Guys

Would this not work for disabling Cut, Copy, Paste mode.

http://www.asap-utilities.com/excel-tips-detail.php?categorie=9&m=85

I have absolutely no idea on how Enable/Disable Macro thing would work other than possibly hiding all the important sheets in a Workbook_Deactivate event then have a button linked to a macro to unhide them on opening thus gettiing round the issue of the user disabling the macro's.

I know security in Excel is pretty dodgy but hopefully the users of this workbook won't want to hack it to bits.

Cheers


Dave
 
Upvote 0

Forum statistics

Threads
1,214,924
Messages
6,122,294
Members
449,077
Latest member
Rkmenon

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