Password Enabling Printing VBA (Specific Sheet)

Rungravee Boonsud

New Member
Joined
Feb 19, 2019
Messages
11
I am looking to LOCK the printing activity in the excel UNLESS the user has a password and specific worksheet.

I am frustrated and need help. Please.

Thank you very much for kindly advise,
Rungravee.
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
must place this in ThisWorkbook module (NOT a standard module)
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
    If Not ActiveSheet.Name = "[COLOR=#ff0000]DataSheet???[/COLOR]" Then
        MsgBox "Cannot print this sheet"
        Cancel = True
    ElseIf Not InputBox("Pssword?") = "[COLOR=#ff0000]123???[/COLOR]" Then
        MsgBox "Wrong password"
        Cancel = True
    End If
End Sub
 
Upvote 0
many thank for advise

and May I have some problem

example

Sheet 1 = Can print No password

Sheet 2 = Cannot print

Sheet 3 = Can print but with password

Do you can advise this case ?
 
Upvote 0
Adapt to suit your exact requirements

If more than one sheet for any Case then list each sheet name separated by comma
Sheet1, Sheet3, Sheet4 are not included inside Select Case below and therefore print normally

Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Select Case ActiveSheet.Name
        Case "Sheet2"[COLOR=#ff0000],[/COLOR] "Sheet5"[COLOR=#ff0000],[/COLOR] "Sheet6"
                MsgBox "Cannot print this sheet"
                Cancel = True

        Case "Sheet3"
            If Not InputBox("Pssword?") = "123???" Then
                MsgBox "Wrong password"
                Cancel = True
            End If
    End Select
End Sub
 
Last edited:
Upvote 0
How about ...
Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)
    Const PW = "[I][COLOR=#ff0000]123???[/COLOR][/I]"
    Dim secret As String:   secret = String(Len(PW), "X")
    Dim msg As String:      msg = "Password?" & vbCr & vbCr & secret
    Select Case ActiveSheet.Name
        Case "Sheet2", "Sheet5", "Sheet6"
                MsgBox "Cannot print this sheet"
                Cancel = True

        Case "Sheet3"
            If Not InputBox(msg, , secret) = PW Then
                MsgBox "Wrong password"
                Cancel = True
            End If
    End Select
End Sub
 
Upvote 0
yongle,

cannot,

it's code show "XXXXXXXXX" before typing a password

but we need show "XXXXXXXXX" after typing a password (fill hidden password)
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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