+ Reply to Thread
Results 1 to 3 of 3

Protection of "View Code" on sheet tab

  1. #1
    Registered User
    Join Date
    01-15-2012
    Location
    Hampshire
    MS-Off Ver
    Excel 2007
    Posts
    38

    Protection of "View Code" on sheet tab

    I have a spreadsheet which uses a macro to hide different rows depending on the values entered into a cell

    The spreadsheet is protected with a password so that password is used in the macro to unprotect the sheet to run the macro and re-protect it when it's finished

    However when the sheet is protected I can still click on the sheet tab and select "View Code" which shows the macro with the embedded password in a VBA window. Is there any way of preventing this while the sheet is protected? I need to prevent users being able to see the password and using it to unprotect the sheet which has many conditional formatting and calculations which may get destroyed if overwritten

    code is

    Private Sub Worksheet_Change(ByVal Target As Range)

    If Not Intersect(Target, Range("B2")) Is Nothing Then
    Application.EnableEvents = False
    Me.Unprotect Password:="andy"
    Range("A6:A60").EntireRow.Hidden = False
    Select Case Range("B2").Value
    Case 999

    Case "one"
    Range("A15, A22, A24:A26, A28:A41, A58:A69").EntireRow.Hidden = True
    Case 100
    Range("A15, A22, A26, A37, A40, A58:A69").EntireRow.Hidden = True
    Case 101
    Range("A15, A22, A24, A26, A37, A40, A58:A69").EntireRow.Hidden = True

    End Select
    Me.Protect Password:="andy"
    Application.EnableEvents = True
    End If

    End Sub
    thanks
    Last edited by orly_sm; 01-30-2013 at 10:54 AM.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Protection of "View Code" on sheet tab

    You have to protect the code separately. In the VBA development window, right-click on the file you are working on. Click on "VBA Project Properties...." and then click the Protection tab. Check "Lock project for viewing" and add a password. Do not forget the password. You could also keep a master copy that is not password protected, then make a copy to protect for distribution to users.

    Also, please note that code tags are required for code. You used "quote" tags. Instead of "quote" use "code". See my signature below.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    01-15-2012
    Location
    Hampshire
    MS-Off Ver
    Excel 2007
    Posts
    38

    Re: Protection of "View Code" on sheet tab

    Thanks for that - just what I needed. Sorry about using the wrong tags - thanks again -Andy

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1