#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default Printing

Hi, Happy New Year to All

I use the code below that is placed in the ThisWorkbook to stop the printing
of certain sheets;

'Stops sheets printing as listed in Case
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Select Case ActiveSheet.Name
Case "Input", "sheet1", "sheet2", "sheet3", "sheet4"
Cancel = True
MsgBox "Sorry, you cannot print this page", vbInformation
End Select
End Sub

Is it possible to amend this to add an If statement to do the following;

Look at cell E162 on sheet 1, if the value is True, sheets 3 and 4 now
print, but sheets 1 & 2 stay so they don't print?

Hope that makes sense.

Regards

Newbeetle
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 694
Default Printing

Hi,

You can do it all in the select statement checking for the true for the two
sheets.

I have introduced a variable cannotprint which is set to true if you cannot
print.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
dim connotprint as boolean
Select Case ActiveSheet.Name
Case "Input", "sheet1", "sheet2"
cannotprint=true
case "sheet3", "sheet4"
cannotprint = worksheets("sheet1").range("E162")
case else
cannotprint=true
end select
if cannotprint then
Cancel = connotprint
MsgBox "Sorry, you cannot print this page", vbInformation
end if
End Sub


Is it possible to amend this to add an If statement to do the following;

Look at cell E162 on sheet 1, if the value is True, sheets 3 and 4 now
print, but sheets 1 & 2 stay so they don't print?


--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Newbeetle" wrote:

Hi, Happy New Year to All

I use the code below that is placed in the ThisWorkbook to stop the printing
of certain sheets;

'Stops sheets printing as listed in Case
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Select Case ActiveSheet.Name
Case "Input", "sheet1", "sheet2", "sheet3", "sheet4"
Cancel = True
MsgBox "Sorry, you cannot print this page", vbInformation
End Select
End Sub

Is it possible to amend this to add an If statement to do the following;

Look at cell E162 on sheet 1, if the value is True, sheets 3 and 4 now
print, but sheets 1 & 2 stay so they don't print?

Hope that makes sense.

Regards

Newbeetle

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Printing

Just a warning...

The user can select multiple sheets and if one of those sheets isn't the
activesheet, that user can print what he/she wants.



Newbeetle wrote:

Hi, Happy New Year to All

I use the code below that is placed in the ThisWorkbook to stop the printing
of certain sheets;

'Stops sheets printing as listed in Case
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Select Case ActiveSheet.Name
Case "Input", "sheet1", "sheet2", "sheet3", "sheet4"
Cancel = True
MsgBox "Sorry, you cannot print this page", vbInformation
End Select
End Sub

Is it possible to amend this to add an If statement to do the following;

Look at cell E162 on sheet 1, if the value is True, sheets 3 and 4 now
print, but sheets 1 & 2 stay so they don't print?

Hope that makes sense.

Regards

Newbeetle


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 98
Default Printing


Hi Martin,

I tried out the code but I'm having a few problems so I've done something
wrong. In case it was other item's in my workbook interfering I made a new
workbook and placed the following code in the VBA Thisworkbook

Private Sub Workbook_BeforePrint(Cancel As Boolean)
Dim connotprint As Boolean
Select Case ActiveSheet.Name
Case "sheet1", "sheet2"
cannotprint = True
Case "sheet3", "sheet4"
cannotprint = Worksheets("sheet1").Range("E1")
Case Else
cannotprint = True
End Select
If cannotprint Then
Cancel = connotprint
MsgBox "Sorry, you cannot print this page", vbInformation
End If
End Sub

I then put test text on the four sheets, when pressing the print button, the
message box appears for each sheet, but when I click the ok button the page
still prints.
I've tried a few things but really I'm a bit lost.

"Martin Fishlock" wrote:

Hi,

You can do it all in the select statement checking for the true for the two
sheets.

I have introduced a variable cannotprint which is set to true if you cannot
print.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
dim connotprint as boolean
Select Case ActiveSheet.Name
Case "Input", "sheet1", "sheet2"
cannotprint=true
case "sheet3", "sheet4"
cannotprint = worksheets("sheet1").range("E162")
case else
cannotprint=true
end select
if cannotprint then
Cancel = connotprint
MsgBox "Sorry, you cannot print this page", vbInformation
end if
End Sub


Is it possible to amend this to add an If statement to do the following;

Look at cell E162 on sheet 1, if the value is True, sheets 3 and 4 now
print, but sheets 1 & 2 stay so they don't print?


--
Hope this helps
Martin Fishlock, Bangkok, Thailand
Please do not forget to rate this reply.


"Newbeetle" wrote:

Hi, Happy New Year to All

I use the code below that is placed in the ThisWorkbook to stop the printing
of certain sheets;

'Stops sheets printing as listed in Case
Private Sub Workbook_BeforePrint(Cancel As Boolean)
Select Case ActiveSheet.Name
Case "Input", "sheet1", "sheet2", "sheet3", "sheet4"
Cancel = True
MsgBox "Sorry, you cannot print this page", vbInformation
End Select
End Sub

Is it possible to amend this to add an If statement to do the following;

Look at cell E162 on sheet 1, if the value is True, sheets 3 and 4 now
print, but sheets 1 & 2 stay so they don't print?

Hope that makes sense.

Regards

Newbeetle

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
Excel 2003 printing problem--printing 1 document on 2 pages Bons Excel Discussion (Misc queries) 0 December 24th 09 04:15 PM
Excel Printing --Borders are not printing on the same page as data Stup88 Excel Discussion (Misc queries) 1 August 7th 07 09:34 AM
Printing a heading on each new page when printing Brian Excel Discussion (Misc queries) 3 November 15th 06 05:22 PM
Enable Double sided printing contiuously when printing multiple s. Lee Excel Discussion (Misc queries) 1 November 27th 04 01:58 AM
Printing? Worksheets not printing the same on multiple pc's! 43fan Excel Programming 2 April 29th 04 02:34 PM


All times are GMT +1. The time now is 10:13 PM.

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"