PC Review


Reply
Thread Tools Rate Thread

BeforePrint event - Jim Thomlinson / pwrichcreek

 
 
Paul D Byrne.
Guest
Posts: n/a
 
      3rd Jun 2008
Hi,

Read the post re 'Get Control Before AND After Printing' and it is exactly
what I am also trying to do - however, I want to differentiate between the
user clicking on Print and on Print Preview. I read somewhere that this isn't
possible - is this right?

Basically the only thing I want to happen when a user prresses either print
or print preivew is the black shading turned to white and the white letters
turned to black on the header and then back again after the event is
finished.

Below is the code I have used so far.

The limitation is I can get the Print Preview or the Print Dialog but not
the print dialog when print is pressed and the print preview when print
preview is pressed.

thanks,

Paul B.

Private Sub Workbook_BeforePrint(Cancel As Boolean)

Dim shtTab As Worksheet
Dim shtStart As Worksheet
Dim rngSelection As Range

On Error GoTo Workbook_BeforePrint_Error

Set shtStart = ActiveSheet
Application.EnableEvents = False
Cancel = True

For Each shtTab In ActiveWorkbook.Sheets

Cells(1, 1).Select

Select Case shtTab.Name

'Sheets I don't want anything to happen to
Case "Summary", "DataHandler"

'Sheets I do
Case Else

With shtTab.Range("1:5")

.Interior.ColorIndex = xlNone
.Font.ColorIndex = xlAutomatic

End With

End Select

Next

'this is the part that doesn't differentiate between Print and Print Preview
ActiveWindow.SelectedSheets.PrintPreview

'OR

Application.Dialogs(xlDialogPrint).Show

For Each shtTab In ActiveWorkbook.Sheets

Cells(1, 1).Select

Select Case shtTab.Name

Case "FFX Check"
Set rngSelection = shtTab.Range("A1:H5")
GoSub ColourSelection

'there are more sheets but this is the gist of it.
End Select

Next

Workbook_BeforePrint_Exit:
Application.EnableEvents = True
shtStart.Activate
Exit Sub


Workbook_BeforePrint_Error:
MsgBox "Error in Print : " & Err.Number _
& vbNewLine & "Error Description : " & Err.Description
Resume Workbook_BeforePrint_Exit

'----------GoSub Procedures---------------------
ColourSelection:
rngSelection.Interior.ColorIndex = 1
rngSelection.Interior.Pattern = xlSolid
rngSelection.Font.ColorIndex = 2
Return

End Sub

 
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
BeforePrint event =?Utf-8?B?RGF2ZSBTaGF3?= Microsoft Excel Programming 3 4th May 2007 05:25 PM
printing macro,want to use beforeprint event? =?Utf-8?B?cGF1bA==?= Microsoft Excel Programming 1 2nd Jul 2006 08:05 PM
Word BeforePrint Event is not raised =?Utf-8?B?bm11ZWdnbGVy?= Microsoft Dot NET 2 12th Aug 2005 11:15 AM
BeforePrint Event Woody Microsoft Excel Programming 2 20th Jul 2005 09:48 AM
BeforePrint event =?Utf-8?B?RW5nbGlzaFRlYWNoZXI=?= Microsoft Excel Programming 4 13th Oct 2004 04:17 PM


Features
 

Advertising
 

Newsgroups
 


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