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

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
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,224,821
Messages
6,181,163
Members
453,021
Latest member
Justyna P

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