+ Reply to Thread
Results 1 to 16 of 16

Protected Sheet Will Not Allow Macro To Run

Hybrid View

  1. #1
    Registered User
    Join Date
    03-16-2009
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Protected Sheet Will Not Allow Macro To Run

    I have protected several sheets in my workbook to protect the forumlas and data for being tempered with by the users.

    When I try to run my macro, I get an error message stating:

    Runtime '1004'
    You can not use this command on a protected sheet

    And the debug is pointing to this part of my code

    Do Until pr > .Cells(1, 1).SpecialCells(xlLastCell).Row
    How can I revise my code to allow me to have my sheets stay protected and still be able to run my macro?
    Last edited by NaNaBoo; 03-27-2009 at 03:48 PM.

  2. #2
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Re: Protected Sheet Will Not Allow Macro To Run

    use following at the top of your code to unprotect the sheet and protect it at the end.

    HTML Code: 

    HTML Code: 


    modytrane

  3. #3
    Registered User
    Join Date
    03-24-2009
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Protected Sheet Will Not Allow Macro To Run

    (I previewed my post and noticed that there was already a response. Maybe someone could provide some input the last section.)

    This is how I've solved this in the past:

    Sheets("Sheet1").Unprotect Password:="password"
    
            'Perform steps on protected cells
    
     Sheets("Sheet1").Protect Password:="password"
    One problem I had is I wanted to keep the password from the people viewing the file, and if you press Alt-F11, VBA pops up showing this code, and therefore the password. I don't know if there is a way around this or if it matters to you either way.
    Oh you wanted the elegant solution? Sorry, that's extra!

  4. #4
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Protected Sheet Will Not Allow Macro To Run

    ^ You have the option of locking/protecting the VBA project. That way, an end user cannot see the code at all, and therefore can't see the password. If the end user does need access to the VBA, your options become more limited.

  5. #5
    Registered User
    Join Date
    03-24-2009
    Location
    New York
    MS-Off Ver
    Excel 2003
    Posts
    25

    Re: Protected Sheet Will Not Allow Macro To Run

    How do you protect the VBA code? I would really like to do this on the file i was working on.

    Thanks!

  6. #6
    Forum Expert
    Join Date
    01-12-2007
    Location
    New Jersey
    Posts
    2,127

    Re: Protected Sheet Will Not Allow Macro To Run

    In the VBE, go to TOOLS-VBAProject Properties. Choose the Protection tab, lock the project, then choose your password.

  7. #7
    Registered User
    Join Date
    03-16-2009
    Location
    California, USA
    MS-Off Ver
    Excel 2003
    Posts
    98

    Re: Protected Sheet Will Not Allow Macro To Run

    THanks,

    I see that I have been given a couple of ways of handling this problem. Let me address the first suggestion and make sure I am understanding this right. In this code;


    ActiveSheet.Unprotect
    ActiveSheet.protect

    Within the macro that needs the sheets to be unprotected, I would include this code at the top and at the bottom?

    I will not include this in the individual protected sheets?

    Please advise.

+ 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