Preventing printing

O

ordnance1

Sorry for the cross posting, but I had posted this to the wrong forum

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
 
J

JLGWhiz

Maybe you could rephrase your posting so someone who has no idea what your
code looks like can understand what you mean. I think you mean that you have
put a before print subroutine in your macro to prevent manual print commands
from the menu bar. But because it runs when your code print command fires,
you cannot execute the print from your code. Is that it?
 
J

Jim Thomlinson

By disabling events in CommandButton2 you will avoid generating the before
print event. Try this...

Private Sub CommandButton2_Click()
on error goto ErrorHandler
application.enableevents = false
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Module2.SortSunday
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Module2.UnSort_AllDays
Unload UserFormPrinting_Sunday

ErrorHandler:
application.enableevents = true
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Preventing printing 1
Printing Macro 1
Printing Macro 4
Pop Up Message before printing 3
Command Button 6
Creating PDF files via 995 1
Printing Excel to CutePDF 3
VB Msgbox result 1

Top