I keep getting a runtime 1004 error in excel due to my macro and worksheet protection

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • JefferyCameron

    #1

    I keep getting a runtime 1004 error in excel due to my macro and worksheet protection

    I am trying to make a macro run while the worksheet is protected.

    The program is to autofilter by color. When you just filter the cell manually, it will work even if the worksheet is protected. However, when I recorded a macro and assigned a "button" to it, the following occured:

    "You cannot use this command on a protected sheet. To use this sheet, you must first unprotect...etc "

    Does anyone know how to autofilter when the worksheet is protected?
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32669

    #2
    Originally posted by JefferyCameron
    JefferyCameron:
    "You cannot use this command on a protected sheet. To use this sheet, you must first unprotect...etc "
    As the message says, To use this sheet, you must first unprotect. That's the point of protection. It stops you making specified changes.

    To unprotect a sheet use :
    Code:
    Call WorkSheet.Protect("{Password}", {Various Boolean Values}, ...)
    Look in the help for those flags that pertain to your version of Access. It's usually a good idea to protect it again when the code is done. I'll include a template for that below :
    Code:
    Call WorkSheet.Unprotect("{Password}")
    NB. If you don't have the password then you won't be able to do it. That's why the designer locked it in the first place.

    Comment

    Working...