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

Searching for Text Not Using a Certain Style

Word is very flexible in what it allows you to search for. One thing it can't do, however, is allow you to search for text ...

Discover More

Calculating Combinations

The COMBIN function is used to determine the number of combinations that can be made from a group of elements. This tip ...

Discover More

Using the System Information Tool

Need to lift the hood and look into the inner workings of Windows? One place you can do this easily is through the System ...

Discover More

Excel Smarts for Beginners! Featuring the friendly and trusted For Dummies style, this popular guide shows beginners how to get up and running with Excel while also helping more experienced users get comfortable with the newest features. Check out Excel 2013 For Dummies today!

MORE EXCELTIPS (MENU)

Specifying a Print Tray for a Worksheet

If you need to modify where a worksheet is printed (meaning, which paper tray it should use), Excel doesn't provide a lot of ...

Discover More

Printing a Worksheet List

Want a list of all the worksheets in your workbook? Here's a short, handy macro that will place all the worksheet names into ...

Discover More

Using Less Paper on Printouts

If a worksheet contains nothing but a bunch of values in column A, you may be loathe to print the worksheet and "waste" a ...

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 for this tip:

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 9 - 7?

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.

Links and Sharing