Disabling Printing

by Allen Wyatt
(last updated July 28, 2014)

8

If you are creating workbooks to be used by others, you may be interested in disabling the print options (menu and toolbar) whenever a specific workbook is open. The easiest way to do so is to use the Auto_Open macro (which runs immediately upon opening the workbook that contains it) to make the menu and toolbar printing commands no longer available. The following will do the trick nicely:

Sub Auto_Open()
    'Prevent Printing via menu
    MenuBars(xlWorksheet).Menus("File").MenuItems("Print...").Delete

    'Turn off Print icon wherever it may be in the toolbars
    For J = 1 To Toolbars.Count
        For K = 1 To Toolbars(J).ToolbarButtons.Count
            If Toolbars(J).ToolbarButtons(K).Id = 2 Then
                Toolbars(J).ToolbarButtons(K).Enabled = False
            End If
            If Toolbars(J).ToolbarButtons(K).Id = 3 Then
                Toolbars(J).ToolbarButtons(K).Enabled = False
            End If
        Next K
    Next J
End Sub

You can also create a special Auto_Close macro that restores the menus and toolbars when the workbook is closed:

Sub Auto_Close()
    'Reset the menu items
    For Each mb In MenuBars
        mb.Reset
    Next mb

    'Reset the buttons
    For J = 1 To Toolbars.Count
        For K = 1 To Toolbars(J).ToolbarButtons.Count
            If Toolbars(J).ToolbarButtons(K).Id = 2 Then
                Toolbars(J).ToolbarButtons(K).Enabled = True
            End If
            If Toolbars(J).ToolbarButtons(K).Id = 3 Then
                Toolbars(J).ToolbarButtons(K).Enabled = True
            End If
        Next K
    Next J
End Sub

You should note that these macros only run when the specific workbook is opened and closed. That means that your printing capability will be unavailable as long as the workbook is open—even for any other open workbooks you may have.

Another approach is to cancel any printing before it starts. The following is a macro you can place within a workbook module:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Cancel = True
End Sub

Whenever someone tries to print the workbook, the process is automatically cancelled. Otherwise, the menu choices and toolbar buttons remain visible. (You could also change the macro to not only cancel but to display a message box indicating that users are not allowed to print.)

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (2556) applies to Microsoft Excel 97, 2000, 2002, and 2003.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He  is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Adding Text to an Envelope

Need to customize the way that Word prints envelopes? There are a couple of approaches you can use, as discussed in this tip.

Discover More

Wrapping Your Text

Want to see all the text that is in a cell, even if it is quite a bit? You need to make sure that text wrapping is turned on, ...

Discover More

Highlighting Cells Containing both Letters and Numbers

Conditional formatting is a great tool for changing the format of cells based on whether certain conditions (rules) are true ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (menu)

Printing Multiple Pages On a Piece of Paper

If you want to save paper on a printout, you might consider printing multiple pages on a single piece of paper. This can be ...

Discover More

Printing Odd or Even Pages

When you print a worksheet, Excel normally prints all the pages or a consecutive series of pages that you specify. If you wan ...

Discover More

Printing Row Numbers

On-screen Excel displays row numbers that help you easily see what is in each row. If you want to print these row numbers, ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is four less than 6?

2015-07-20 18:01:19

Mike

Does this work if macros are disabled, as is standard practice when initially opening excel files these days?


2015-04-20 07:33:28

Barry

@Margus

The "Workbook_BeforePrint" will intercept any request to print (even if it is from a macro). So to allow a macro to print I would create a global variable, say "AllowPrinting" which is set just before your macro wants to print, and reset in the "Workbook_BeforePrint" routine:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If AllowPrinting = False then
Cancel = True
End If
AllowPrinting = False
End Sub
This should be placed in the "ThisWorkBook" code page.

Sub YourCode()
....... your code
....... your code
AllowPrinting =True
Worksheets("Sheet1").Printout
....... your code
....... your code
End sub
The .Printout method is using default settings but can have quite a few parameters if required.

The variable "AllowPrinting" should be declared on a "Module" page outside of any routine.

Public AllowPrinting as Boolean


2015-04-20 04:35:42

Margus

Is there any way I could disable normal printing for all files, but users should be able to print with set macro.


2014-12-20 06:06:25

Barry

@Vuke
I suggest the following macro which only allows "Sheet2" to be printed if it is the "active" sheet:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
if Activesheet.Name<>"Sheet2" then
Cancel = True
End If
End Sub

This should be placed in the "ThisWorkBook" code page, and the name of sheet2 should be substituted in the "If...." statement.


2014-12-19 09:38:46

Vuke

I have a workbook with two worksheets, I do not want clerks to be able to print sheet 1 but to print sheet 2 only. Reply to my address.


2014-10-07 05:17:58

Himanshu

Pls explain when their is no macro enable but still printing options are not getting enable.


2014-09-22 11:31:56

John

Does not work. Have tried numerous suggestions and all fail to prevent printing.


2014-07-16 15:59:14

Chris

Your variables are not defined so this will not run.


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.