PC Review


Reply
Thread Tools Rate Thread

Before_Print

 
 
JMay
Guest
Posts: n/a
 
      12th Nov 2006
Often I only want to Print Preview a Doc
What is necessary in the Before_Print Code
So that when I click on the Close button in the Print-Preview screen.
I am returned to my worksheet INSTEAD of the printer cranking
Up and beginning to print my umpteen pages UNNECESSARILY.

Thanks,


 
Reply With Quote
 
 
 
 
=?Utf-8?B?SmF5?=
Guest
Posts: n/a
 
      12th Nov 2006
Hi JMay -

I'd suggest "flipping" the order of the commands that are issued to Excel.
Currently, you issue a Print request followed by a PrintPreview request. Try
starting with a PrintPreview request as follows:

Delete the Before_Print event code that controls printing. Put the
following line in a standard procedure in a VBA module and run it when you
want to preview the print job:

activesheet.printpreview <---change active sheet to whatever you want printed

Then, from the print preview dialog that appears, press the [Print...]
button if you want a hard copy or [Close] if you don't.

--
Jay


"JMay" wrote:

> Often I only want to Print Preview a Doc
> What is necessary in the Before_Print Code
> So that when I click on the Close button in the Print-Preview screen.
> I am returned to my worksheet INSTEAD of the printer cranking
> Up and beginning to print my umpteen pages UNNECESSARILY.
>
> Thanks,
>
>
>

 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      12th Nov 2006
Why not just use the Print Preview toolbar button?

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"JMay" <(E-Mail Removed)> wrote in message
news:c1u5h.34685$(E-Mail Removed)...
> Often I only want to Print Preview a Doc
> What is necessary in the Before_Print Code
> So that when I click on the Close button in the Print-Preview screen.
> I am returned to my worksheet INSTEAD of the printer cranking
> Up and beginning to print my umpteen pages UNNECESSARILY.
>
> Thanks,
>
>



 
Reply With Quote
 
JMay
Guest
Posts: n/a
 
      12th Nov 2006
Bob, thanks -- but here is my code:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim lrow As Long
Dim rng As Range
lrow = Range("B65536").End(xlUp).Row
Set rng = Range("A5:C" & lrow)
With ActiveSheet
.PageSetup.PrintArea = rng.Address
.PrintPreview
End With
End Sub

It seems that I need an additional statement above, because when
I click on the Close button which appears on the Preview Screen
My Printer takes-off printing the 40 (unwanted) sheets, grrrrrr..




"Bob Phillips" <(E-Mail Removed)> wrote in message
news:#U1a$#(E-Mail Removed):

> Why not just use the Print Preview toolbar button?
>
> --
> HTH
>
> Bob Phillips
>
> (replace somewhere in email address with gmail if mailing direct)
>
> "JMay" <(E-Mail Removed)> wrote in message
> news:c1u5h.34685$(E-Mail Removed)...
> > Often I only want to Print Preview a Doc
> > What is necessary in the Before_Print Code
> > So that when I click on the Close button in the Print-Preview screen.
> > I am returned to my worksheet INSTEAD of the printer cranking
> > Up and beginning to print my umpteen pages UNNECESSARILY.
> >
> > Thanks,
> >
> >


 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      12th Nov 2006
Try this

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim lrow As Long
Dim rng As Range
Application.EnableEvents = False
lrow = Range("B65536").End(xlUp).Row
Set rng = Range("A5:C" & lrow)
With ActiveSheet
.PageSetup.PrintArea = rng.Address
.PrintPreview
Cancel = True
End With
Application.EnableEvents = True
End Sub



but I still don't understand why you don't just cut the code abd use the
button.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"JMay" <(E-Mail Removed)> wrote in message
news:3rF5h.32505$(E-Mail Removed)...
> Bob, thanks -- but here is my code:
>
> Private Sub Workbook_BeforePrint(Cancel As Boolean)
> Dim lrow As Long
> Dim rng As Range
> lrow = Range("B65536").End(xlUp).Row
> Set rng = Range("A5:C" & lrow)
> With ActiveSheet
> .PageSetup.PrintArea = rng.Address
> .PrintPreview
> End With
> End Sub
>
> It seems that I need an additional statement above, because when
> I click on the Close button which appears on the Preview Screen
> My Printer takes-off printing the 40 (unwanted) sheets, grrrrrr..
>
>
>
>
> "Bob Phillips" <(E-Mail Removed)> wrote in message
> news:#U1a$#(E-Mail Removed):
>
> > Why not just use the Print Preview toolbar button?
> >
> > --
> > HTH
> >
> > Bob Phillips
> >
> > (replace somewhere in email address with gmail if mailing direct)
> >
> > "JMay" <(E-Mail Removed)> wrote in message
> > news:c1u5h.34685$(E-Mail Removed)...
> > > Often I only want to Print Preview a Doc
> > > What is necessary in the Before_Print Code
> > > So that when I click on the Close button in the Print-Preview screen.
> > > I am returned to my worksheet INSTEAD of the printer cranking
> > > Up and beginning to print my umpteen pages UNNECESSARILY.
> > >
> > > Thanks,
> > >
> > >

>



 
Reply With Quote
 
JMay
Guest
Posts: n/a
 
      12th Nov 2006
Also...
I am triggering this Before_Print event by clicking on the Toolbar
Button PRINT-PREVIEW (if that matters).
Jim


"JMay" <(E-Mail Removed)> wrote in message
news:3rF5h.32505$(E-Mail Removed):

> Bob, thanks -- but here is my code:
>
> Private Sub Workbook_BeforePrint(Cancel As Boolean)
> Dim lrow As Long
> Dim rng As Range
> lrow = Range("B65536").End(xlUp).Row
> Set rng = Range("A5:C" & lrow)
> With ActiveSheet
> .PageSetup.PrintArea = rng.Address
> .PrintPreview
> End With
> End Sub
>
> It seems that I need an additional statement above, because when
> I click on the Close button which appears on the Preview Screen
> My Printer takes-off printing the 40 (unwanted) sheets, grrrrrr..
>
>
>
>
> "Bob Phillips" <(E-Mail Removed)> wrote in message
> news:#U1a$#(E-Mail Removed):
>
> > Why not just use the Print Preview toolbar button?
> >
> > --
> > HTH
> >
> > Bob Phillips
> >
> > (replace somewhere in email address with gmail if mailing direct)
> >
> > "JMay" <(E-Mail Removed)> wrote in message
> > news:c1u5h.34685$(E-Mail Removed)...
> > > Often I only want to Print Preview a Doc
> > > What is necessary in the Before_Print Code
> > > So that when I click on the Close button in the Print-Preview screen.
> > > I am returned to my worksheet INSTEAD of the printer cranking
> > > Up and beginning to print my umpteen pages UNNECESSARILY.
> > >
> > > Thanks,
> > >
> > >


 
Reply With Quote
 
JMay
Guest
Posts: n/a
 
      12th Nov 2006
Bob, thanks for your patience. I see your 2 adds to my code.
1)EnableEvents Off/On and 2) Cancel = True
This however creates another Q,
When I now click on the Toolbar button PRINT-PREVIEW
The Event (below) is Triggered,,

I thought all code was run in the order layed-out in a procedure.

If let's say the Application.EnableEvents = False WAS OMITTED
Wouldn't the code continue on thru the Set rng = Range("A5:C" & lrow)
Looks like the line Cancel = True is VOIDING anything and everything,
Even tough the .PrintPreview line preceeds it.

I'm not getting why the use of the EnableEvents, off and on;
Pretty confused at this point, Can you straighten me out?

TIA,

Jim

"Bob Phillips" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed):

> Try this
>
> Private Sub Workbook_BeforePrint(Cancel As Boolean)
> Dim lrow As Long
> Dim rng As Range
> Application.EnableEvents = False
> lrow = Range("B65536").End(xlUp).Row
> Set rng = Range("A5:C" & lrow)
> With ActiveSheet
> .PageSetup.PrintArea = rng.Address
> .PrintPreview
> Cancel = True
> End With
> Application.EnableEvents = True
> End Sub
>
>
>
> but I still don't understand why you don't just cut the code abd use the
> button.
>
> --
> HTH
>
> Bob Phillips
>
> (replace somewhere in email address with gmail if mailing direct)
>
> "JMay" <(E-Mail Removed)> wrote in message
> news:3rF5h.32505$(E-Mail Removed)...
> > Bob, thanks -- but here is my code:
> >
> > Private Sub Workbook_BeforePrint(Cancel As Boolean)
> > Dim lrow As Long
> > Dim rng As Range
> > lrow = Range("B65536").End(xlUp).Row
> > Set rng = Range("A5:C" & lrow)
> > With ActiveSheet
> > .PageSetup.PrintArea = rng.Address
> > .PrintPreview
> > End With
> > End Sub
> >
> > It seems that I need an additional statement above, because when
> > I click on the Close button which appears on the Preview Screen
> > My Printer takes-off printing the 40 (unwanted) sheets, grrrrrr..
> >
> >
> >
> >
> > "Bob Phillips" <(E-Mail Removed)> wrote in message
> > news:#U1a$#(E-Mail Removed):
> >
> > > Why not just use the Print Preview toolbar button?
> > >
> > > --
> > > HTH
> > >
> > > Bob Phillips
> > >
> > > (replace somewhere in email address with gmail if mailing direct)
> > >
> > > "JMay" <(E-Mail Removed)> wrote in message
> > > news:c1u5h.34685$(E-Mail Removed)...
> > > > Often I only want to Print Preview a Doc
> > > > What is necessary in the Before_Print Code
> > > > So that when I click on the Close button in the Print-Preview screen.
> > > > I am returned to my worksheet INSTEAD of the printer cranking
> > > > Up and beginning to print my umpteen pages UNNECESSARILY.
> > > >
> > > > Thanks,
> > > >
> > > >

> >


 
Reply With Quote
 
JMay
Guest
Posts: n/a
 
      12th Nov 2006
Bob, Can the Cancel = True be moved form inside the With Activesheet
group to Outside it like so:
With ActiveSheet
.PageSetup.PrintArea = rng.Address
.PrintPreview
End With
Cancel = True
Application.EnableEvents = True

Thanks,

Jim


"Bob Phillips" <(E-Mail Removed)> wrote in message
news:#(E-Mail Removed):

> Try this
>
> Private Sub Workbook_BeforePrint(Cancel As Boolean)
> Dim lrow As Long
> Dim rng As Range
> Application.EnableEvents = False
> lrow = Range("B65536").End(xlUp).Row
> Set rng = Range("A5:C" & lrow)
> With ActiveSheet
> .PageSetup.PrintArea = rng.Address
> .PrintPreview
> Cancel = True
> End With
> Application.EnableEvents = True
> End Sub
>
>
>
> but I still don't understand why you don't just cut the code abd use the
> button.
>
> --
> HTH
>
> Bob Phillips
>
> (replace somewhere in email address with gmail if mailing direct)
>
> "JMay" <(E-Mail Removed)> wrote in message
> news:3rF5h.32505$(E-Mail Removed)...
> > Bob, thanks -- but here is my code:
> >
> > Private Sub Workbook_BeforePrint(Cancel As Boolean)
> > Dim lrow As Long
> > Dim rng As Range
> > lrow = Range("B65536").End(xlUp).Row
> > Set rng = Range("A5:C" & lrow)
> > With ActiveSheet
> > .PageSetup.PrintArea = rng.Address
> > .PrintPreview
> > End With
> > End Sub
> >
> > It seems that I need an additional statement above, because when
> > I click on the Close button which appears on the Preview Screen
> > My Printer takes-off printing the 40 (unwanted) sheets, grrrrrr..
> >
> >
> >
> >
> > "Bob Phillips" <(E-Mail Removed)> wrote in message
> > news:#U1a$#(E-Mail Removed):
> >
> > > Why not just use the Print Preview toolbar button?
> > >
> > > --
> > > HTH
> > >
> > > Bob Phillips
> > >
> > > (replace somewhere in email address with gmail if mailing direct)
> > >
> > > "JMay" <(E-Mail Removed)> wrote in message
> > > news:c1u5h.34685$(E-Mail Removed)...
> > > > Often I only want to Print Preview a Doc
> > > > What is necessary in the Before_Print Code
> > > > So that when I click on the Close button in the Print-Preview screen.
> > > > I am returned to my worksheet INSTEAD of the printer cranking
> > > > Up and beginning to print my umpteen pages UNNECESSARILY.
> > > >
> > > > Thanks,
> > > >
> > > >

> >


 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      12th Nov 2006
Jim,

If you don't suppress events, the procedure is entered twice, once for the
original print/print preview, and then again when it meets the PrintPreview
in the code). Nothing seems to happen then.

The Cancel is cancelling the original print request as you want to force a
print preview.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"JMay" <(E-Mail Removed)> wrote in message
news:OjG5h.32821$(E-Mail Removed)...
> Bob, thanks for your patience. I see your 2 adds to my code.
> 1)EnableEvents Off/On and 2) Cancel = True
> This however creates another Q,
> When I now click on the Toolbar button PRINT-PREVIEW
> The Event (below) is Triggered,,
>
> I thought all code was run in the order layed-out in a procedure.
>
> If let's say the Application.EnableEvents = False WAS OMITTED
> Wouldn't the code continue on thru the Set rng = Range("A5:C" & lrow)
> Looks like the line Cancel = True is VOIDING anything and everything,
> Even tough the .PrintPreview line preceeds it.
>
> I'm not getting why the use of the EnableEvents, off and on;
> Pretty confused at this point, Can you straighten me out?
>
> TIA,
>
> Jim
>
> "Bob Phillips" <(E-Mail Removed)> wrote in message
> news:#(E-Mail Removed):
>
> > Try this
> >
> > Private Sub Workbook_BeforePrint(Cancel As Boolean)
> > Dim lrow As Long
> > Dim rng As Range
> > Application.EnableEvents = False
> > lrow = Range("B65536").End(xlUp).Row
> > Set rng = Range("A5:C" & lrow)
> > With ActiveSheet
> > .PageSetup.PrintArea = rng.Address
> > .PrintPreview
> > Cancel = True
> > End With
> > Application.EnableEvents = True
> > End Sub
> >
> >
> >
> > but I still don't understand why you don't just cut the code abd use the
> > button.
> >
> > --
> > HTH
> >
> > Bob Phillips
> >
> > (replace somewhere in email address with gmail if mailing direct)
> >
> > "JMay" <(E-Mail Removed)> wrote in message
> > news:3rF5h.32505$(E-Mail Removed)...
> > > Bob, thanks -- but here is my code:
> > >
> > > Private Sub Workbook_BeforePrint(Cancel As Boolean)
> > > Dim lrow As Long
> > > Dim rng As Range
> > > lrow = Range("B65536").End(xlUp).Row
> > > Set rng = Range("A5:C" & lrow)
> > > With ActiveSheet
> > > .PageSetup.PrintArea = rng.Address
> > > .PrintPreview
> > > End With
> > > End Sub
> > >
> > > It seems that I need an additional statement above, because when
> > > I click on the Close button which appears on the Preview Screen
> > > My Printer takes-off printing the 40 (unwanted) sheets, grrrrrr..
> > >
> > >
> > >
> > >
> > > "Bob Phillips" <(E-Mail Removed)> wrote in message
> > > news:#U1a$#(E-Mail Removed):
> > >
> > > > Why not just use the Print Preview toolbar button?
> > > >
> > > > --
> > > > HTH
> > > >
> > > > Bob Phillips
> > > >
> > > > (replace somewhere in email address with gmail if mailing direct)
> > > >
> > > > "JMay" <(E-Mail Removed)> wrote in message
> > > > news:c1u5h.34685$(E-Mail Removed)...
> > > > > Often I only want to Print Preview a Doc
> > > > > What is necessary in the Before_Print Code
> > > > > So that when I click on the Close button in the Print-Preview

screen.
> > > > > I am returned to my worksheet INSTEAD of the printer cranking
> > > > > Up and beginning to print my umpteen pages UNNECESSARILY.
> > > > >
> > > > > Thanks,
> > > > >
> > > > >
> > >

>



 
Reply With Quote
 
Bob Phillips
Guest
Posts: n/a
 
      12th Nov 2006
That should be fine, as it is not a method of the activesheet, but an
argument of the procedure.

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"JMay" <(E-Mail Removed)> wrote in message
news:uAG5h.33385$(E-Mail Removed)...
> Bob, Can the Cancel = True be moved form inside the With Activesheet
> group to Outside it like so:
> With ActiveSheet
> .PageSetup.PrintArea = rng.Address
> .PrintPreview
> End With
> Cancel = True
> Application.EnableEvents = True
>
> Thanks,
>
> Jim
>
>
> "Bob Phillips" <(E-Mail Removed)> wrote in message
> news:#(E-Mail Removed):
>
> > Try this
> >
> > Private Sub Workbook_BeforePrint(Cancel As Boolean)
> > Dim lrow As Long
> > Dim rng As Range
> > Application.EnableEvents = False
> > lrow = Range("B65536").End(xlUp).Row
> > Set rng = Range("A5:C" & lrow)
> > With ActiveSheet
> > .PageSetup.PrintArea = rng.Address
> > .PrintPreview
> > Cancel = True
> > End With
> > Application.EnableEvents = True
> > End Sub
> >
> >
> >
> > but I still don't understand why you don't just cut the code abd use the
> > button.
> >
> > --
> > HTH
> >
> > Bob Phillips
> >
> > (replace somewhere in email address with gmail if mailing direct)
> >
> > "JMay" <(E-Mail Removed)> wrote in message
> > news:3rF5h.32505$(E-Mail Removed)...
> > > Bob, thanks -- but here is my code:
> > >
> > > Private Sub Workbook_BeforePrint(Cancel As Boolean)
> > > Dim lrow As Long
> > > Dim rng As Range
> > > lrow = Range("B65536").End(xlUp).Row
> > > Set rng = Range("A5:C" & lrow)
> > > With ActiveSheet
> > > .PageSetup.PrintArea = rng.Address
> > > .PrintPreview
> > > End With
> > > End Sub
> > >
> > > It seems that I need an additional statement above, because when
> > > I click on the Close button which appears on the Preview Screen
> > > My Printer takes-off printing the 40 (unwanted) sheets, grrrrrr..
> > >
> > >
> > >
> > >
> > > "Bob Phillips" <(E-Mail Removed)> wrote in message
> > > news:#U1a$#(E-Mail Removed):
> > >
> > > > Why not just use the Print Preview toolbar button?
> > > >
> > > > --
> > > > HTH
> > > >
> > > > Bob Phillips
> > > >
> > > > (replace somewhere in email address with gmail if mailing direct)
> > > >
> > > > "JMay" <(E-Mail Removed)> wrote in message
> > > > news:c1u5h.34685$(E-Mail Removed)...
> > > > > Often I only want to Print Preview a Doc
> > > > > What is necessary in the Before_Print Code
> > > > > So that when I click on the Close button in the Print-Preview

screen.
> > > > > I am returned to my worksheet INSTEAD of the printer cranking
> > > > > Up and beginning to print my umpteen pages UNNECESSARILY.
> > > > >
> > > > > Thanks,
> > > > >
> > > > >
> > >

>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Before_Print event Jan Kronsell Microsoft Excel Programming 3 28th Aug 2008 08:49 PM
Before_Print =?Utf-8?B?Um9iaW4gQ2xheQ==?= Microsoft Excel Programming 2 13th Feb 2007 12:41 PM
before_print does not work - f8 key does not do anything Nasim Microsoft Excel Programming 2 4th Dec 2006 02:03 AM
Re-Post: Before_Print Sub Doesn't Trigger =?Utf-8?B?UGhpbCBIYWdlbWFu?= Microsoft Excel Programming 27 4th Mar 2004 04:03 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:00 AM.