+ Reply to Thread
Results 1 to 12 of 12

Worksheet Protection when using VBA

  1. #1
    Registered User
    Join Date
    05-08-2006
    Posts
    77

    Worksheet Protection when using VBA

    I have a worksheet that I want to protect, but when I use the protect worksheet command on the tools menu, it renders all of my VBA useless.

    I saw an option that says
    Please Login or Register  to view this content.
    It doesn't seem to work. I have it at the top of my worksheet code area. Should I put it elsewhere?

    I need for my users to only be able to change very specific cells.

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229
    The code you posted should work. It sets the UserInterfaceOnly to True. If you also want it to protect the sheet, you need to set the other arguments.
    Please Login or Register  to view this content.

  3. #3
    Registered User
    Join Date
    05-08-2006
    Posts
    77
    Should this be in a module, or on the sheet code? Or maybe on the workbook code?

  4. #4
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    It should be in a general module, although it will work in the sheet or workbook modules. If you need to change cells with your VBA code that are protected, you will need to first unprotect the sheet, run the code, then reprotect the sheet after the code is complete.

    Jason

  5. #5
    Registered User
    Join Date
    05-08-2006
    Posts
    77
    I don't think that's what I'm looking for.

    I need to be able to have the entire sheet protected all the time, except for cells that the user is allowed to change. The code is going to paste images on my main sheet (copied from another in the workbook) depending on the user selection in validation drop down boxes.

    The document itself will be out of my hands. I need for the users to never ever be able to change anything other than what I am allowing them to change.

  6. #6
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    The problem is that if you want to manipulate the sheets, you will need to unprotect it in the code, then reprotect it. The users will still be unable to change any of the unlocked cells, since the unprotecting and reprotecting will be transparent to them.

  7. #7
    Registered User
    Join Date
    05-08-2006
    Posts
    77
    Are you able to describe exactly how to do this? I'm still just learning VBA and having a tough time understanding how to make this happen.

  8. #8
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    Ok, let me give you an example. Let's assume this is your macro:
    Please Login or Register  to view this content.
    You will need to unprotect the sheet, run the code, and then reprotect it as follows:
    Please Login or Register  to view this content.
    Does this help?

    Jason

  9. #9
    Registered User
    Join Date
    05-08-2006
    Posts
    77
    I will try that, thank you.

  10. #10
    Registered User
    Join Date
    05-08-2006
    Posts
    77
    This worked very well. Thank you. One minor glitch that I need help with. This is all based on a Worksheet Change code. I have one extra area in my sheet with a simple validation list done with the toolbar options. When I change this list, it unprotects my worksheet.

    Please Login or Register  to view this content.
    If the change does not occur within my target column, I need it to reprotect the worksheet, which would clear up this unprotecting issue on the validation list. Where exactly do I write the Activesheet.Protect "password" in relation to the Then GoTo leave line.

  11. #11
    Forum Expert
    Join Date
    12-29-2004
    Location
    Michigan, USA
    MS-Off Ver
    2013
    Posts
    2,208
    You need to include it somewhere between
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    Jason

  12. #12
    Registered User
    Join Date
    05-08-2006
    Posts
    77
    That did the trick!! Thanks so much for your patience and help!

+ 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