+ Reply to Thread
Results 1 to 9 of 9

Protect and Unprotect using vba

  1. #1
    Registered User
    Join Date
    12-06-2008
    Location
    Syracuse
    Posts
    64

    Protect and Unprotect using vba

    Good Morning,

    I would like to run the below code on a protected workbook on a shared drive.
    I am not quite sure how to do this. What I basically need to do is on the user pressing the button that runs the code, it would unprotect>write data>save>protect again.

    Thanks for any suggestions!!!

    HTML Code: 

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Hi,

    Is the workbook/worksheet password protected, and if so do you know what it is?

    Rgds

  3. #3
    Registered User
    Join Date
    12-06-2008
    Location
    Syracuse
    Posts
    64
    hi...the workbook is not password protected....just protected cells.

  4. #4
    Registered User
    Join Date
    12-06-2008
    Location
    Syracuse
    Posts
    64
    the workbook is not password protected. The cells are protected and the password is GrayMck1425...Also, I have a Macro Button that will not run if the sheet is protected...Any ideas for that?

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Hi,

    Just use the following instruction in the workbook open event. Adjust the sheet reference as necessary. e.g. instead of ActiveSheet (which will run the macro on whichever sheet happens to be active when the WB loads), use Sheet1, Sheet2 etc...

    Please Login or Register  to view this content.
    HTH

  6. #6
    Registered User
    Join Date
    12-06-2008
    Location
    Syracuse
    Posts
    64
    Just to clarify....

    I have a button on my main workbook that gets pressed and sends data to an outside workbook automatically.
    I would like to protect the outside workbook. This is a workbook that only I will open.

    example.... wb 1(this is the one the employees will interact with and has the export button)

    employee opens this wb, hits the "submit results" button, and specific data is sent to an outside workbook to be evaluated.

    This whole process is automated. The issue is that the wb where the results are going need to be protected. I need to add something to the above code, that when it automatically open, it unprotects, writes the data, resets protection, and saves, and closes.

    The only part I don't have is it being protected.
    If I try to protect it and run the code, I get an error that I need to "unprotect" the receiving wb.

    Hope this makes sense????

    Thanks

  7. #7
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Hi,

    Just include the .Unprotect instruction in the workbook open event as the first line, and as the last line use

    Please Login or Register  to view this content.
    HTH

  8. #8
    Registered User
    Join Date
    12-06-2008
    Location
    Syracuse
    Posts
    64
    so i would just add that to the code in my original post in the main wb?

  9. #9
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464
    Hi,

    Yes that's right. Just make the two lines of code I gave you the first and last lines in the procedure you mentioned in your OP.

    Rgds

+ 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