Solved

How can I set password for a sheet in excel

Posted on 2016-10-28
4
80 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 20

Expert Comment

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

Featured Post

Want Experts Exchange at your fingertips?

With Experts Exchange’s latest app release, you can now experience our most recent features, updates, and the same community interface while on-the-go. Download our latest app release at the Android or Apple stores today!

Question has a verified solution.

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

Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

635 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