Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / November 2007

Tip: Looking for answers? Try searching our database.

Preventing printing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
ordnance1@comcast.net - 23 Nov 2007 20:03 GMT
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
JLGWhiz - 23 Nov 2007 20:25 GMT
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?

> Sorry for the cross posting, but I had posted this to the wrong forum
>
[quoted text clipped - 25 lines]
>
> End Sub
JLGWhiz - 23 Nov 2007 20:40 GMT
Try setting you Cancel = False and see if that cures the problem.

> Sorry for the cross posting, but I had posted this to the wrong forum
>
[quoted text clipped - 25 lines]
>
> End Sub
Jim Thomlinson - 23 Nov 2007 21:06 GMT
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

Signature

HTH...

Jim Thomlinson

> Sorry for the cross posting, but I had posted this to the wrong forum
>
[quoted text clipped - 25 lines]
>
> End Sub
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.