+ Reply to Thread
Results 1 to 2 of 2

Programmatically Protect/Unprotect Sheets with VBA

  1. #1
    Registered User
    Join Date
    03-28-2010
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    60

    Programmatically Protect/Unprotect Sheets with VBA

    Good Morning,

    I have a workbook with many sheets that contain a mixture of cells that are locked and unlocked. Is it possible to programmatically Protect/Unprotect a given sheet with a pass word? Basically, I have macros that update locked cells, but the macro fails b/c the cells are locked. I need to be able to unlock the sheet via VBA, execute my macro and the relock the protected cells. The password can be in the VBA code b/c I will have the VBA project locked for viewing.

    I recorded a macro of me doing what the locking part of it, but I dont see how to insert a password. Here is the recorded code:

    Please Login or Register  to view this content.
    What I would like is something like this:

    Please Login or Register  to view this content.
    Thank you for any help that can be provided

    learning_vba
    Last edited by learning_vba; 08-07-2014 at 09:53 AM. Reason: solved

  2. #2
    Registered User
    Join Date
    03-28-2010
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    60

    Re: Programmatically Protect/Unprotect Sheets with VBA

    I have found a solution which works for my needs. Instead on protecting/unprotecting sheets, I can use the following line in my For Each ws loop:

    ws.Protect Password:="abc123", UserInterfaceOnly:=True

    Apparently this only protects cells from the user interface, but on the VBA side of things protected cells can be modified

    Thank you

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro to Unprotect sheets-unlock range of cells-protect sheets
    By jrace in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-09-2013, 10:45 AM
  2. [SOLVED] protect/unprotect all sheets
    By wayneg in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-03-2012, 08:20 AM
  3. [SOLVED] Password protect and unprotect all sheets EXCEPT two named sheets
    By Ducatisto in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-29-2012, 05:43 AM
  4. protect/unprotect all sheets
    By roos in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-13-2006, 06:50 PM
  5. Unprotect and protect vba code programmatically
    By greenfalcon in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-23-2005, 05:11 AM

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