Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 4
Default Preventing printing

I want to prevent ptinting of my workbook without using the macro I
have set up for printing. I entered the code below to prevent
printing, but it also prevents my macro from printing. Any ideas how I
can get around this, or it an all or nothing kind of thing? Also below
is my print macro.


Private Sub Workbook_BeforePrint(Cancel As Boolean)
msg = MsgBox("Sorry, printing is disabled for this workbook.",
vbCritical)
Cancel = True
End Sub



Private Sub CommandButton2_Click()

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

Module2.SortSunday

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

Module2.UnSort_AllDays

Unload UserFormPrinting_Sunday

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,441
Default Preventing printing

At the top of a regular code module, declare a public Boolean

Public AllowPrint As Boolean

Then change your code like this:

Private Sub Workbook_Open()
AllowPrint = False
End Sub

Private Sub Workbook_BeforePrint(Cancel As Boolean)
If AllowPrint Then Exit Sub
msg = MsgBox("Sorry, printing is disabled for this workbook.",
vbCritical)
Cancel = True
End Sub

Private Sub CommandButton2_Click()
AllowPrint = True
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Module2.SortSunday
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Module2.UnSort_AllDays
Unload UserFormPrinting_Sunday
AllowPrint = False
End Sub

HTH,
Bernie
MS Excel MVP

wrote in message
...
I want to prevent ptinting of my workbook without using the macro I
have set up for printing. I entered the code below to prevent
printing, but it also prevents my macro from printing. Any ideas how I
can get around this, or it an all or nothing kind of thing? Also below
is my print macro.


Private Sub Workbook_BeforePrint(Cancel As Boolean)
msg = MsgBox("Sorry, printing is disabled for this workbook.",
vbCritical)
Cancel = True
End Sub



Private Sub CommandButton2_Click()

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

Module2.SortSunday

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True

Module2.UnSort_AllDays

Unload UserFormPrinting_Sunday

End Sub



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
preventing printing in Excel misscrf Excel Discussion (Misc queries) 3 January 3rd 07 08:15 PM
can I ensure a drop down list is used i.e by preventing printing Have a Go Excel Discussion (Misc queries) 1 December 15th 06 04:27 AM
Preventing Formula Changes Jen New Users to Excel 1 December 7th 06 11:56 PM
preventing copying mattguerilla Excel Discussion (Misc queries) 3 May 24th 06 03:40 PM
Preventing cell contents from printing Blair Scanlan Excel Discussion (Misc queries) 5 December 20th 04 12:39 AM


All times are GMT +1. The time now is 03:24 PM.

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

About Us

"It's about Microsoft Excel"