+ Reply to Thread
Results 1 to 10 of 10

Error trying to run macro on protected sheet

  1. #1
    Forum Contributor
    Join Date
    05-30-2021
    Location
    Colorado Springs
    MS-Off Ver
    Microsoft 365
    Posts
    173

    Error trying to run macro on protected sheet

    I'm trying to run a macro that copies data from one workbook to several hundred others, and because the sheet in the several hundred that I want to copy to is protected, I of course get an error.

    This sheet-level code isn't allowing me to circumvent the error. Where am I going wrong?

    Please Login or Register  to view this content.

  2. #2
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Error trying to run macro on protected sheet

    That is a setting you would apply, each time a workbook is opened, to protect the workbook.
    It is not a setting that will override any existing protection a user has in place.

    For you code to work you will need to unprotect users workbooks.
    Cheers
    Andy
    www.andypope.info

  3. #3
    Forum Contributor
    Join Date
    05-30-2021
    Location
    Colorado Springs
    MS-Off Ver
    Microsoft 365
    Posts
    173

    Re: Error trying to run macro on protected sheet

    OK. Got it. Once I use the macro to take hundreds of identical files and customize them with copied over data, how then can I get a macro into all of those customized files that is designed to protect a certain sheet automatically upon file save/close. Without opening them one at a time and creating the macro, that is. It's a chicken and egg thing.

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Error trying to run macro on protected sheet

    Confused. If you know the password to all these files why not simple use it to unprotect the worksheet, add your data and then protect the sheet again?

    In order to get code into the workbooks you would need to write code using functions and methods from the vbe library.
    http://www.cpearson.com/Excel/VBE.aspx

  5. #5
    Forum Contributor
    Join Date
    05-30-2021
    Location
    Colorado Springs
    MS-Off Ver
    Microsoft 365
    Posts
    173

    Re: Error trying to run macro on protected sheet

    It's complicated, but the templates contain a macro that always keeps the sheet protected. I just need them unprotected as a one time thing so I can run the data copy macro. Then, whenever the file is opened again it becomes automatically protected again. I think I can do what I need if you could help me on some code that will unprotect just the "TargetWorksheet" sheet in all workbooks (stored in the same folder) that are named like this: FileCopy001.xlsm, FileCopy002.xlsm, etc.

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Error trying to run macro on protected sheet

    So do you know the password for the templates? If so you should be able to use Unprotect

  7. #7
    Forum Contributor
    Join Date
    05-30-2021
    Location
    Colorado Springs
    MS-Off Ver
    Microsoft 365
    Posts
    173

    Re: Error trying to run macro on protected sheet

    Yep, I know the password. It's always the same. The issue is that there is no way around deploying the templates in anything but a protected state (well, the one sheet that gets protected, anyway), even if I wanted to because a macro inside forces protection on file close. And so I need to unprotect all as a one time thing before I apply all the copied data. Hundreds and hundreds of files. Can't open each one and manually unprotect. When the data copy macro finishes running, all files will save and close and be protected, which is just what is needed. There's a mix of users involved - some are authorized to tinker with the sheet and know the passwords, others not. I need to relieve the authorized tinkerers of having to remember to reprotect the sheets.
    Last edited by kyle4570; 06-28-2021 at 03:35 AM.

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Error trying to run macro on protected sheet

    You unprotect as part of the copy data macro.

    psuedo code would be

    for each template workbook
    open workbook
    unprotect sheet with known password
    copy data
    save and close workbook

  9. #9
    Forum Contributor
    Join Date
    05-30-2021
    Location
    Colorado Springs
    MS-Off Ver
    Microsoft 365
    Posts
    173

    Re: Error trying to run macro on protected sheet

    Where would it get wedged in to this?

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    05-30-2021
    Location
    Colorado Springs
    MS-Off Ver
    Microsoft 365
    Posts
    173

    Re: Error trying to run macro on protected sheet

    Figured it out. I was hoping I could accomplish it through the same macro that copies the data. And that's exactly what you helped me get to. 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 error when sheet is protected
    By maxpower2 in forum Excel - New Users/Basics
    Replies: 5
    Last Post: 04-15-2020, 03:49 PM
  2. [SOLVED] Macro error for protected sheet
    By bryden2008 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-13-2017, 04:17 PM
  3. [SOLVED] Macro Button Error on Protected Sheet
    By mwatson2 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-12-2015, 10:14 AM
  4. [SOLVED] Macro Giving Error On Protected Sheet
    By isc0rpi0 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 03-09-2013, 01:07 AM
  5. Error- Running a Macro on a Protected Sheet
    By nacho in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-20-2007, 08:21 PM
  6. [SOLVED] Macro Error when Sheet is Protected
    By Johnny in forum Excel General
    Replies: 6
    Last Post: 07-28-2006, 02:45 PM
  7. [SOLVED] macro on protected sheet-error
    By michaelberrier in forum Excel General
    Replies: 6
    Last Post: 06-11-2006, 01:35 PM

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