stopping a sheet from printing

Acehole

Board Regular
Joined
Sep 29, 2009
Messages
249
hello people who know lots of stuff,
how do i stop a sheet from being printed and add an error message/ dialogue box saying this sheet cannot be printed, view only etc etc.
this to appear when they goto the print option in the menus.
thanks in advance.
Acehole
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
hello, i have managed to find this code, however it stops all of the sheets being printed, i require only selected sheets not to be printed.

Private Sub Workbook_BeforePrint(Cancel As Boolean)
MsgBox "Printing of these pages is not permitted ", vbInformation, "COMPUTER SAYS NO"
Cancel = True
End Sub

thanks
Acehole
 
Upvote 0
i'm shocked at you guys, normally get a response from someone,
any reason why not? even if it is abuse for being so poor ar VBA,
Ace.
 
Upvote 0
i'm shocked at you guys

Hoping this is in jest, and that you dont treat this as a IT helpdesk rather than a learning resource.

Anyways, code below does the job and handles multiple sheets

Code:
Option Explicit

Private Sub Workbook_BeforePrint(Cancel As Boolean)

Dim bln As Boolean

bln = InRange

If bln = True Then
    MsgBox "Printing of these pages is not permitted ", vbInformation, "COMPUTER SAYS NO"
    Cancel = InRange
End If


End Sub

Function InRange() As Boolean

Dim ws As Variant
Dim i As Long

Set ws = ActiveWindow.SelectedSheets
InRange = False

For i = 1 To ws.Count

    Select Case ws(i).Name
        Case "Sheet1", "Sheet2" 'etc etc
            InRange = True
    End Select

Next i

End Function

Hoep it helps
 
Upvote 0
thank you for that worked spot on, as i'm sure you knew it would.
now to find out what all the terms in the code mean.
thanks again
Ace.
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,258
Members
452,901
Latest member
LisaGo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top