![]() |
overriding the print button and File/Print
Hello:
I have a model that I want to override the ability to print only one page. The model has 3 pages and the first page needs to be printed first always before any of the others. Can a macro be written that attaches to the model that only allows printing from a custom print macro? Or, something that when the user hits the toolbar print button (or File...Print...) the model always prints the first page too? |
overriding the print button and File/Print
Pablo,
The code below (place it in the "ThisWorkbook" module) stops all printing unless the instruction to print comes from one of your printing macros. Private Sub Workbook_BeforePrint(Cancel As Boolean) Cancel = True End Sub use something like this to print, put in a normal module Sub print_this() Application.EnableEvents = False 'your print macro here Application.EnableEvents = True End Sub -- Paul B Always backup your data before trying something new Using Excel 97 & 2000 Please post any response to the newsgroups so others can benefit from it ** remove news from my email address to reply by email ** "Pablo" wrote in message om... Hello: I have a model that I want to override the ability to print only one page. The model has 3 pages and the first page needs to be printed first always before any of the others. Can a macro be written that attaches to the model that only allows printing from a custom print macro? Or, something that when the user hits the toolbar print button (or File...Print...) the model always prints the first page too? |
overriding the print button and File/Print
Seeing that there is a way to block basic commands like "Print", what
are the other commands to cancel say "Save"? Is there a list (Web site?) that shows all the terms/syntax to do this? For example, using: Private Sub Workbook_BeforePrint(Cancel As Boolean) Cancel = True End Sub Can I subsitute "Save" where "print" is and you cannot save a wb? Also, is there a way to put a password on the workbook that activates the commands if a pw is entered? |
overriding the print button and File/Print
Pablo, you can use this to keep the workbook form being saved
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean) Cancel = True End Sub you could use something like this to ask for a password to print, Of course all this can be disabled if somebody opens the workbook with macros disabled Private Sub Workbook_BeforePrint(Cancel As Boolean) 'must lock VBA project so you can't see the password in it 'put in this workbook module Dim myPassword As String myPassword = InputBox(prompt:="Please enter the password to proceed:", _ Title:="Password is required to print this file.") 'change password to what you want If myPassword < "password" Then MsgBox prompt:="Click OK To Return To The Workbook.", _ Title:="Print Cancelled -- Correct Password Not Entered", _ Buttons:=16 Cancel = True Else End If End Sub "Pablo" wrote in message om... Seeing that there is a way to block basic commands like "Print", what are the other commands to cancel say "Save"? Is there a list (Web site?) that shows all the terms/syntax to do this? For example, using: Private Sub Workbook_BeforePrint(Cancel As Boolean) Cancel = True End Sub Can I subsitute "Save" where "print" is and you cannot save a wb? Also, is there a way to put a password on the workbook that activates the commands if a pw is entered? |
All times are GMT +1. The time now is 02:57 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com