Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Still stumped with printing macro


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Still stumped with printing macro

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Still stumped with printing macro


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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Still stumped with printing macro

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   Report Post  
Posted to microsoft.public.excel.programming
GS GS is offline
external usenet poster
 
Posts: 364
Default Still stumped with printing macro

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
stumped LarryK Excel Worksheet Functions 4 March 28th 09 05:54 PM
Stumped bad, need help please! Kevin Excel Worksheet Functions 10 April 12th 08 10:36 PM
Stumped Jake Excel Discussion (Misc queries) 4 November 21st 06 01:09 PM
Stumped Andibevan[_4_] Excel Programming 6 December 23rd 05 03:03 PM
Stumped Sheeny[_21_] Excel Programming 3 June 23rd 04 07:28 PM


All times are GMT +1. The time now is 02:50 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"