Excel

Restrict User To 1 Sheet

Ease of Use

Easy

Version tested with

2000 

Submitted by:

lucas

Description:

There are several sheets in the book but you only want to allow users access to 1 sheet. 

Discussion:

You may not want to hide other sheets in the book for some reason but you only want the user to be able to access 1 sheet which you determine. Note: This is a very low level of security, more likely use would be for convenience where users would not try to bypass the effect. It can be easily defeated by simply setting their macro security level to high. If you need more security try Johskie's kb entry: Force User to Enable Macros: located at: http://www.vbaexpress.com/kb/getarticle.php?kb_id=578 

Code:

instructions for use

			

Put this code In the ThisWorkbook module: Option Explicit Private Sub Workbook_SheetActivate(ByVal Sh As Object) 'Change the 1 in the following line to the 'sheet you wish to allow. All other sheets are restricted Worksheets(1).Activate End Sub

How to use:

  1. Open the Visual Basic Editor by going to tools-Macro's-Visual Basic Editor or use Alt-F11
  2. In the Project Explorer double click the ThisWorkbook object
  3. In the module pane paste the code above.
  4. Close the Visual Basic Editor by clicking the X in the upper right corner or go to File-Close
 

Test the code:

  1. Save and close the workbook
  2. Open the workbook again and you will only be able to access sheet1
 

Sample File:

user_can_only_access_sheet1.zip 5.89KB 

Approved by mdmackillop


This entry has been viewed 421 times.

Please read our Legal Information and Privacy Policy
Copyright @2004 - 2020 VBA Express