+ Reply to Thread
Results 1 to 5 of 5

Thread: Code Error When Sheet Is Protected

  1. #1
    Valued Forum Contributor
    Join Date
    07-10-2008
    Location
    UK
    Posts
    219

    Code Error When Sheet Is Protected

    Hi Everyone

    I am using a button on a worksheet to excecute the following code:

    Private Sub HideExamples()
    
    If Rows("6:7").EntireRow.Hidden = False Then
        Rows("6:7").EntireRow.Hidden = True
        
        Sheet2.Shapes("Button 15").TextFrame.Characters.Text = ("View Examples")
        
    Else
        Rows("6:7").EntireRow.Hidden = False
        
        Sheet2.Shapes("Button 15").TextFrame.Characters.Text = ("Hide Examples")
        
    End If
    
    End Sub
    It works perfectly when the sheet is unprotected but not when it is protected. the rows are not locked and neither is the button.

    Any ideas whats going on??

  2. #2
    Valued Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    Hi twofootgiant,

    Add the line of code below:

    Sheets("Sheet Name").Unprotect
    and then after all of the code is complete put this at the end

    Sheets("Sheet Name").Protect
    (If sheet is passworded then use)

    Sheets("Sheet Name").Unprotect "Password HERE"
    
    Sheets("Sheet Name").Protect "Password HERE"
    There are only 10 types of people in the world:
    Those who understand binary, and those who don't!

  3. #3
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,639
    The best way is to use Worksheet Protection with UserInterFace Only, see the details & example workbook here

    http://www.excel-it.com/vba_examples.htm
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

  4. #4
    Valued Forum Contributor
    Join Date
    07-10-2008
    Location
    UK
    Posts
    219
    genius...thankyou :D

  5. #5
    Valued Forum Contributor Stuie's Avatar
    Join Date
    09-17-2006
    Location
    Suffolk, UK
    MS-Off Ver
    Excel 2003/2007
    Posts
    432
    Hope you was calling me a genius lol, prob royUK .

    no probs
    There are only 10 types of people in the world:
    Those who understand binary, and those who don't!

+ 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.2.0