Solved

How can I set password for a sheet in excel

Posted on 2016-10-28
4
50 Views
Last Modified: 2016-10-28
Hello experts,

I need to give password to one of the sheets in my excel file. I have two excel sheets in my workbook (Input, and Report).

I want to give password to "Report" sheet.

thanks for your help!
0
Comment
Question by:tony01excel tony
4 Comments
 
LVL 5

Accepted Solution

by:
Yamaafg earned 400 total points
ID: 41863920
Hi,

Try below code. Change the password from 123456 to whatever you would like it to be.You need to enter this code in the main workheet in vba and save your file as as xlsm.

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
'to password protect Report Sheet
Dim xSheetName As String
xSheetName = "Report"
If Application.ActiveSheet.Name = xSheetName Then
    Application.EnableEvents = False
    Application.ActiveSheet.Visible = False
    xTitleId = "Please Enter The Password"
    response = Application.InputBox("Password", xTitleId, "", Type:=2)
    If response = "123456" Then
        Application.Sheets(xSheetName).Visible = True
        Application.Sheets(xSheetName).Select
    End If
End If
Application.Sheets(xSheetName).Visible = True
Application.EnableEvents = True
End Sub
0
 
LVL 19

Assisted Solution

by:Zaheer Iqbal
Zaheer Iqbal earned 100 total points
ID: 41863933
0
 

Author Closing Comment

by:tony01excel tony
ID: 41863940
Great, thanks for the quick help guys. The first solution with vba code worked well.
1
 
LVL 18

Expert Comment

by:Roy_Cox
ID: 41864063
That code does not protect the sheet at all!
0

Featured Post

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question