Home |
Search |
Today's Posts |
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() I'll be the first to admit that I'm a rookie at this whole VBA thing. All of the code that I'm currently using in my workbook is totally accredited to information I've found through searching and posting in this forum. I have virtually no comprehension of the syntax or logic involved in writing my own code. So, please feel free to answer this question in the most elementary way possible. I've successfully employed code to prevent users of my workbook from printing. The following code was written to "This Workbook": Private Sub Workbook_BeforePrint(Cancel As Boolean) Cancel = True MsgBox "Information contained in this workbook cannot be printed" End Sub Here is my problem...I cannot seem to find a way to trigger this event with a button instead of triggering upon opening the workbook. There are some instances where a few users (with password privileges) may have to print a page from the workbook before forwarding it on to the ultimate end user who cannot print anything. If there was some way to toggle this print prevention with a button it would be perfect! Can anyone help?? -- zenahs ------------------------------------------------------------------------ zenahs's Profile: http://www.excelforum.com/member.php...o&userid=28681 View this thread: http://www.excelforum.com/showthread...hreadid=515420 |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
Hi zenahs
You can create a button that change the EnableEvents Sub test() Application.EnableEvents = False ActiveSheet.PrintOut Application.EnableEvents = True End Sub -- Regards Ron de Bruin http://www.rondebruin.nl "zenahs" wrote in message ... I'll be the first to admit that I'm a rookie at this whole VBA thing. All of the code that I'm currently using in my workbook is totally accredited to information I've found through searching and posting in this forum. I have virtually no comprehension of the syntax or logic involved in writing my own code. So, please feel free to answer this question in the most elementary way possible. I've successfully employed code to prevent users of my workbook from printing. The following code was written to "This Workbook": Private Sub Workbook_BeforePrint(Cancel As Boolean) Cancel = True MsgBox "Information contained in this workbook cannot be printed" End Sub Here is my problem...I cannot seem to find a way to trigger this event with a button instead of triggering upon opening the workbook. There are some instances where a few users (with password privileges) may have to print a page from the workbook before forwarding it on to the ultimate end user who cannot print anything. If there was some way to toggle this print prevention with a button it would be perfect! Can anyone help?? -- zenahs ------------------------------------------------------------------------ zenahs's Profile: http://www.excelforum.com/member.php...o&userid=28681 View this thread: http://www.excelforum.com/showthread...hreadid=515420 |
#3
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]() Thanks Ron. I've copied this macro into the workbook and attached it to a button. Unfortunately, when I press the button the active sheet prints. Am doing something wrong? Is there a way to deactivate printing for the entire workbook instea of just the active sheet -- zenah ----------------------------------------------------------------------- zenahs's Profile: http://www.excelforum.com/member.php...fo&userid=2868 View this thread: http://www.excelforum.com/showthread.php?threadid=51542 |
#4
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I think you have EnableEvents set to False
Or you have disable macro's when you open the workbook Run this one time Application.EnableEvents = True Save and close/reopen the file Now you can't use the Print button if you have your code in the Workbook_BeforePrint in the thisworkbook module With the code I posted you can prin the activesheet now -- Regards Ron de Bruin http://www.rondebruin.nl "zenahs" wrote in message ... Thanks Ron. I've copied this macro into the workbook and attached it to a button. Unfortunately, when I press the button the active sheet prints. Am I doing something wrong? Is there a way to deactivate printing for the entire workbook instead of just the active sheet? -- zenahs ------------------------------------------------------------------------ zenahs's Profile: http://www.excelforum.com/member.php...o&userid=28681 View this thread: http://www.excelforum.com/showthread...hreadid=515420 |
#5
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
This should do what you want:
Private Sub Workbook_BeforePrint(Cancel As Boolean) dim sPassword as String sPassword = InputBox("Enter the password") if Not sPassword = "WhatEverThePasswordIs" Then Cancel = True MsgBox "Information contained in this workbook cannot be printed" Else ActiveSheet.PrintOut End If End Sub Regards, GS |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
stumped | Excel Worksheet Functions | |||
Stumped bad, need help please! | Excel Worksheet Functions | |||
Stumped | Excel Discussion (Misc queries) | |||
Stumped | Excel Programming | |||
Stumped | Excel Programming |