Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35
Default Workbook_BeforePrint performs twice ?

Hi there,

I've put this code in the Workbook_BeforePrint event and when choosing a
printpreview I notice that when pressing escape, Excel shows the preview
again. Only after pressing the escape for the second time, Excel goes back
to normal view.

Code:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Application.EnableEvents = False
If ActiveSheet.Name = "Weekform" Then ActiveSheet.PageSetup.PrintArea =
_
Range("Weekform_PRINT").Address
If Range("User") = "" Then Range("User") = UserName 'Using JWalk's
function for retrieving logged-in user
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Application.EnableEvents = True
End Sub

How do I prevent the second printpreview, and therefore also the second
printing of the sheet when not going for the preview ?

I've tried using "Cancel = True" right after the Private Sub
Workbook_BeforePrint(Cancel As Boolean) line.
Seems not to work

TIA,
Peter



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Workbook_BeforePrint performs twice ?

You can add Cancel=true and stop the procedure from running normally (you're
controlling the printing).

But you can print sheets that aren't active. You may want to use something
like:

Option Explicit

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Application.EnableEvents = False
With Worksheets("weekform")
.PageSetup.PrintArea = .Range("Weekform_PRINT").Address
If .Range("User") = "" Then
.Range("User") = UserName
'Using JWalk's function for retrieving logged-in user
End If
End With

ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Application.EnableEvents = True
Cancel = True
End Sub

You're changing that .printarea each time you print, but so what???



Peter wrote:

Hi there,

I've put this code in the Workbook_BeforePrint event and when choosing a
printpreview I notice that when pressing escape, Excel shows the preview
again. Only after pressing the escape for the second time, Excel goes back
to normal view.

Code:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Application.EnableEvents = False
If ActiveSheet.Name = "Weekform" Then ActiveSheet.PageSetup.PrintArea =
_
Range("Weekform_PRINT").Address
If Range("User") = "" Then Range("User") = UserName 'Using JWalk's
function for retrieving logged-in user
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Application.EnableEvents = True
End Sub

How do I prevent the second printpreview, and therefore also the second
printing of the sheet when not going for the preview ?

I've tried using "Cancel = True" right after the Private Sub
Workbook_BeforePrint(Cancel As Boolean) line.
Seems not to work

TIA,
Peter


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Workbook_BeforePrint performs twice ?

I think it shows the print a second time because you are doing a
printout in the macro. The BeforePrint event gives you a chance to make
changes before the print job is sent to the printer. You can stop the
print job by setting Cancel to false. Since you do not set Cancel to
false you end up with two requests!

Terry


Peter wrote:
Hi there,

I've put this code in the Workbook_BeforePrint event and when choosing a
printpreview I notice that when pressing escape, Excel shows the preview
again. Only after pressing the escape for the second time, Excel goes back
to normal view.

Code:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Application.EnableEvents = False
If ActiveSheet.Name = "Weekform" Then ActiveSheet.PageSetup.PrintArea =
_
Range("Weekform_PRINT").Address
If Range("User") = "" Then Range("User") = UserName 'Using JWalk's
function for retrieving logged-in user
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Application.EnableEvents = True
End Sub

How do I prevent the second printpreview, and therefore also the second
printing of the sheet when not going for the preview ?

I've tried using "Cancel = True" right after the Private Sub
Workbook_BeforePrint(Cancel As Boolean) line.
Seems not to work

TIA,
Peter



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,758
Default Workbook_BeforePrint performs twice ?

I think you'll actually want to set cancel = true.





Terry Shannon wrote:

I think it shows the print a second time because you are doing a
printout in the macro. The BeforePrint event gives you a chance to make
changes before the print job is sent to the printer. You can stop the
print job by setting Cancel to false. Since you do not set Cancel to
false you end up with two requests!

Terry

Peter wrote:
Hi there,

I've put this code in the Workbook_BeforePrint event and when choosing a
printpreview I notice that when pressing escape, Excel shows the preview
again. Only after pressing the escape for the second time, Excel goes back
to normal view.

Code:

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Application.EnableEvents = False
If ActiveSheet.Name = "Weekform" Then ActiveSheet.PageSetup.PrintArea =
_
Range("Weekform_PRINT").Address
If Range("User") = "" Then Range("User") = UserName 'Using JWalk's
function for retrieving logged-in user
ActiveWindow.SelectedSheets.PrintOut Copies:=1, Collate:=True
Application.EnableEvents = True
End Sub

How do I prevent the second printpreview, and therefore also the second
printing of the sheet when not going for the preview ?

I've tried using "Cancel = True" right after the Private Sub
Workbook_BeforePrint(Cancel As Boolean) line.
Seems not to work

TIA,
Peter




--

Dave Peterson
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
create a drop down list that performs a task DL9998 Excel Discussion (Misc queries) 2 April 28th 07 05:04 PM
Performs illegal operation on save MariaS Excel Discussion (Misc queries) 1 March 3rd 05 07:29 PM
disable print option, not Workbook_BeforePrint Andoni[_4_] Excel Programming 0 July 27th 04 11:40 PM
Workbook_BeforePrint Squid[_2_] Excel Programming 2 May 11th 04 04:18 PM
Problem - Workbook_BeforePrint JON-JON Excel Programming 3 August 26th 03 01:19 PM


All times are GMT +1. The time now is 01:38 AM.

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"