Urgent Help Needed!
Thanks Thanks:  0
Likes Likes:  0
Results 1 to 3 of 3

Thread: Urgent Help Needed!

  1. #1
    New Member
    Join Date
    Mar 2002
    Posts
    3
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

     
    Help! I am running a macro that hides rows with a button click and then hides the same columns with another button click, but I need to protect my worksheet. I have tried unprotecting all the cells included in the hide/unhide macro but it won't run the macro with the protection on. It works fine when not protected.

    Why? Can I overcome this?

  2. #2
    Board Regular
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio, USA
    Posts
    6,824
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default

    Hi
    Click Tools, Protection, Unprotect Sheet and hope someone did not enter a password.
    Tom

  3. #3
    MrExcel MVP Joe Was's Avatar
    Join Date
    Feb 2002
    Location
    Central Florida, USA
    Posts
    7,539
    Post Thanks / Like
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Default

      
    You need to run an un-lock around your code.

    Try using the code below.

    put form buttons on the sheet to lock and unlock, the password is hardcoded into the VBA code and hidden. This way the user cannot change the password.

    This code gos on the sheet module:

    Private Sub Worksheet_Change(ByVal Target As Range)
    '
    ' Macro by Joseph S. Was
    '
    Application.EnableEvents = False

    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True, Password:="admin"
    Application.EnableEvents = True
    End Sub

    This code gos on the module:

    Sub myUnLock()
    'This code will unprotect the sheet.
    Application.EnableEvents = False
    Application.DisplayAlerts = False
    ActiveSheet.Unprotect ("admin")

    'Add optional code here!

    Application.EnableEvents = True
    Application.DisplayAlerts = True

    End Sub

    This is a very simple form of this.
    If this is the route you want to try, I have some very complex systems?

    Note: The password is hard-coded.

    The unprotect will automatically be re-protected by the first macro when the unprotect is done. JSW


User Tag List

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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

 

 
DMCA.com