Welcome toExcel.Tips.Net
Tips.Net Home
ExcelTips Home
Ask an Excel Question
Make a Comment
ExcelTips FAQ
ExcelTips Premium
Learn Access Now
Free Printable Forms
Beauty Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Legal Tips
Money Tips
Organizing Tips
Pest Tips
Pet Tips
Wedding Tips
Word2007 Tips
WordTips
Advertise on the
ExcelTips Site
Filtering Columns for Unique Values
Printing Multiple Worksheets on a Single Page
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 versions: 97 2000 2002 2003 2007
Change Formatting Based On Your Data! Conditional formatting provides a way for you to adjust the appearance of your data based on the data itself. Discover how to put this amazingly powerful feature to work for you, today. This comprehensive volume is available in two editions.