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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
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
oops :oops:
Sheet1, Sheet3, Sheet4 are not included inside Select Case ...
should be ...

Sheet1
& Sheet4 are not included inside Select Case ...
 
Last edited:
Upvote 0
Yongle,

May I Have one question,

when typing a password for printing, Can we show hidden password (ex. xxxxxxx) ?

thank for your respond :)
 
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,213,534
Messages
6,114,186
Members
448,554
Latest member
Gleisner2

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