Prevent Printing an Excel Workbook

Contents

If you, for some reason, want to prevent other users from printing your Excel workbook, then you can use a simple trick.

Press combination Alt + F11to open the Visual Basic Editor, or use the button Visual Basic tab developer (Developer). Find the module in the upper left corner of the Project window This book (ThisWorkbook) and open it by double-clicking the left mouse button:

Prevent Printing an Excel Workbook

In the window that opens, copy and paste the simple macro code:

  Private Sub Workbook_BeforePrint(Cancel As Boolean) Cancel = True MsgBox "Printing of this workbook is prohibited!", vbCritical End Sub  

Technically, this code is an event handler for sending a document to print. Team Cancel=True cancels the standard Excel workflow in this case, i.e. printout, replacing it with a blocking message:

Prevent Printing an Excel Workbook

Of course, the user can generally disable all macros in the book and our macro will not work. However, there is also a proven recipe for this case: hide all sheets of the book, except for one (with a message about the need to enable macros) and force the user to allow them 😉

  • Monitor user sign-in to an Excel workbook
  • 4 Ways to Protect Data in Excel
  • How to make a sheet super hidden

Leave a Reply