+ Reply to Thread
Results 1 to 14 of 14

Running Macros when worksheets are protected

  1. #1
    Registered User
    Join Date
    04-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    20

    Running Macros when worksheets are protected

    Hi all,

    I have a number of worksheets with simple macros for buttons which i would like to run, they work fine when the worksheets are not password protected, but i need all worksheets to be password protected so users are only able to change a certain amount of unlocked cells.

    i know from other posts on here the way forwrad should be to put something at the start and end of the macros to unprotect the worksheet with the password and then put the password back on but can someone please help with the exact coding, one of my macros is as follows:

    Sub Macro4()
    '
    ' Macro4 Macro
    '
    Sheets("Master Data").Select
    Range("L10").Select
    ActiveSheet.ShowAllData
    ActiveSheet.Range("$A$10:$FI$102").AutoFilter Field:=4, Criteria1:=Array( _
    "BAFO", "Bid", "Go", "Prospect", "Suspect", "="), Operator:=xlFilterValues
    ActiveSheet.Range("$A$10:$FI$102").AutoFilter Field:=8, Criteria1:="Yes"

    End Sub

  2. #2
    Forum Contributor Dave H9's Avatar
    Join Date
    03-10-2011
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    418

    Re: Running Macros when worksheets are protected

    Hi,

    To unprtect at start of code -

    Please Login or Register  to view this content.
    And protect at end -

    Please Login or Register  to view this content.
    Alter password and sheet name as required.

    Hope that helps

    Dave H
    - Mark your post [SOLVED] if it has been answered satisfactorily, by editing your original post using advanced mode.
    - Thank those that provided useful help, its nice and its very well appreciated...use the star on the lower left of the post

  3. #3
    Registered User
    Join Date
    04-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Running Macros when worksheets are protected

    thanks Dave i added that in and it works for some macros and the others it keeps coming up with the error 1004 - showalldata method of worksheet class failed and in the macro it is highlighting the following step:

    ActiveSheet.ShowAllData

    any ideas?

  4. #4
    Forum Contributor Dave H9's Avatar
    Join Date
    03-10-2011
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    418

    Re: Running Macros when worksheets are protected

    In the ones it is not working on are you definatley selecting the sheet first? In you posted example this is the -
    Please Login or Register  to view this content.
    Dave H

  5. #5
    Registered User
    Join Date
    04-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Running Macros when worksheets are protected

    no the macro buttons are in an "overview" tab and the buttons take them to different sections of the "master Data" tab, i think the problem may be to do with autofilters as i am trying to reset all the autofilters at the beginning of each of the macros.

  6. #6
    Forum Contributor Dave H9's Avatar
    Join Date
    03-10-2011
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    418

    Re: Running Macros when worksheets are protected

    Can you post a sample sheet please and I'll see if I can spot the problem?

    Dave H

  7. #7
    Registered User
    Join Date
    04-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Running Macros when worksheets are protected

    sample attached, thanks dave.
    Last edited by cbrow236; 04-17-2013 at 05:09 AM.

  8. #8
    Forum Contributor Dave H9's Avatar
    Join Date
    03-10-2011
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    418

    Re: Running Macros when worksheets are protected

    Sorry - no attachment.

    To add attachment hit "Go advanced" then "manage attachments".

    Dave H

  9. #9
    Registered User
    Join Date
    04-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Running Macros when worksheets are protected

    Attachment 228721sorry attachment shoudl now be atatched.

  10. #10
    Forum Contributor Dave H9's Avatar
    Join Date
    03-10-2011
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    418

    Re: Running Macros when worksheets are protected

    Hi,

    Not quite sure how to solve this one. You need to somehow check the existing filter conditions before you apply the new. The code bugs out on "Showalldata" when no filters have been applied to the target range.

    I'll see what I can do, but in the meantime hopefully someone with better VBA knowledge will pitch in.

    Dave H

  11. #11
    Registered User
    Join Date
    04-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Running Macros when worksheets are protected

    thanks for your help Dave.

  12. #12
    Forum Contributor Dave H9's Avatar
    Join Date
    03-10-2011
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    418

    Re: Running Macros when worksheets are protected

    Actually, ignore my last post.

    Check through your macros and make sure you have not commented out either the protect or unprotect command. I found a few when trying to debug and lo and behold all macros began working.

    Hope that solves this for you?

    Dave H

  13. #13
    Registered User
    Join Date
    04-15-2013
    Location
    UK
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: Running Macros when worksheets are protected

    thats amazing, i didnt realise some of them were highlighted green and commented out, i have changed them all and they now all work, thanks so much for your help dave!!

  14. #14
    Forum Contributor Dave H9's Avatar
    Join Date
    03-10-2011
    Location
    Manchester, England
    MS-Off Ver
    Excel 2007
    Posts
    418

    Re: Running Macros when worksheets are protected

    Hi cbrow,

    Glad that helped, btw I think there will still be a problem with your code if no filters have been applied, so if you find this to be the case tryreplacing -

    Please Login or Register  to view this content.
    with

    Please Login or Register  to view this content.
    Good Luck

    Dave H

+ 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