+ Reply to Thread
Results 1 to 4 of 4

Run VBA on Protected worksheet

  1. #1
    Registered User
    Join Date
    03-14-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    2

    Run VBA on Protected worksheet

    Hi

    I am having a similar problem to Bob@sun.

    I am new at VBA's and can't figure out how to incorporate the 'Userinterfaceonly" part into my code

    Basically:
    - I want If column 3 (i.e. c) is zero, then I want to hide rows 44-57 , 66-69, and 91 - 104
    - This works until i protect the worksheet
    - I have tried to incorporate 'ActiveSheet.Unprotect Passsword: ='Secret' and ActiveSheet.Unprotect Password:="Secret" but can't subsequently unprotect my worksheet

    How can I run VBA in a protected worksheet without it subsequently being all protected?

    this is my code:

    Please Login or Register  to view this content.

    Any help with telling me how my code should be is much appreciated!!

    thanks
    Last edited by JBeaucaire; 03-14-2013 at 01:56 AM. Reason: Added code tags, as per forum rules. Don't forget!

  2. #2
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Run VBA on Protected worksheet

    The UserInterfaceOnly flag has to be turned on each time the sheet is opened and/or unlocked and relocked. That particular parameter does not survive the closing of the workbook... dumb, but that's how it is.

    So, you're code will work as is, it appears you are using the more common technique of simply unprotecting, doing your stuff, and then protecting again. That works, and it introduces no headaches like UserInterfaceOnly can do if it gets turned off somehow and all your macros stop working. Is it really worth the effort?


    BTW, don't forget CODE tags, I've added them to the post above, you'll need to do that from now on, OK?
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  3. #3
    Registered User
    Join Date
    03-14-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Excel 2010
    Posts
    2

    Re: Run VBA on Protected worksheet

    ah - sorry, will do CODE tags from now on.

    Also my code up there says 'unprotect' on the second last line, it actually says 'protect' (otherwise i get the code error '400')

    So everything stays protected after run it, how do I unprotect it?
    Last edited by Dukes; 03-14-2013 at 02:27 AM.

  4. #4
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: Run VBA on Protected worksheet

    Quote Originally Posted by Dukes View Post
    ....how do I unprotect it?
    By taking that line completely out.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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