+ Reply to Thread
Results 1 to 8 of 8

Code sticks when workbook protected

  1. #1
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Code sticks when workbook protected

    I have a stack of code running in a spreadsheet or two. The workbooks and sheets are protected but they are open to allow VBA to make changes. So far so good.

    I have the following draft giving me problems though.
    Please Login or Register  to view this content.
    Runs just fine when unlocked etc. But if it is locked up I get "Application-defined or object-defined error". What am I missing?

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,821

    Re: Code sticks when workbook protected

    The macro will have to unprotect and then protect the sheet. Change the password (in red) to suit your needs.
    Please Login or Register  to view this content.
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: Code sticks when workbook protected

    I really wanted to avoid that. Besides I'm a bit confused when after opening the workbook (and once again since to make sure of it) the following code has been run.

    Please Login or Register  to view this content.
    wsh is just the holder for all sheets to be cycled through. This allows all other code re style changes, content changes etc to be made by code so why not this particular bit of code?
    Last edited by malcmail; 07-31-2019 at 10:11 AM.

  4. #4
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: Code sticks when workbook protected

    Even unlocked the code is not working now. Swear I'll never understand the oddities of VBA! Ignore that - that was down to idiot. But the original issue still remains.

  5. #5
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,915

    Re: Code sticks when workbook protected

    The UIO parameter is not 100% reliable. For some things you still may have to unprotect and reprotect, which is a real pain in more recent versions as that's a lot slower than it used to be. Of course, that's not an issue for you on 2003...
    Rory

  6. #6
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331
    Quote Originally Posted by rorya View Post
    The UIO parameter is not 100% reliable. For some things you still may have to unprotect and reprotect, which is a real pain in more recent versions as that's a lot slower than it used to be. Of course, that's not an issue for you on 2003...
    It now runs twice. Once on opening, once on pressing a start button. All other choice works ok so why would this bit take exception? Oh we've moved on now. No more 2003, so now we can actually do stuff (just not always quickly)

  7. #7
    Forum Expert rorya's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365 Ent Monthly Channel / Insiders Beta
    Posts
    8,915

    Re: Code sticks when workbook protected

    You might want to update your profile then.

    As to why it takes exception, as I said, that parameter is just not 100% reliable.

  8. #8
    Forum Contributor
    Join Date
    03-11-2013
    Location
    United Kingdom
    MS-Off Ver
    Excel 2016 (among others!)
    Posts
    331

    Re: Code sticks when workbook protected

    Good point - I'll get that changed.

    I think I have found the culprit though. Need to add "DrawingObjects:=True," to the protection line - seems to work OK then.

+ 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] VBA code to update query from a password protected excel workbook and then close workbook
    By MrChipper in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-14-2017, 07:41 AM
  2. Hiding Code In Protected Workbook
    By 4lowie in forum Excel General
    Replies: 1
    Last Post: 12-20-2013, 02:54 AM
  3. How to open a protected workbook from VBA code?
    By khalidlblid in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-03-2013, 06:25 AM
  4. VBA Code for Renaming Worksheets in Protected Workbook
    By drjanand in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-19-2013, 12:39 PM
  5. unable to close password protected workbook using VBA code in another workbook
    By abulooz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-04-2012, 08:54 AM
  6. code to update very hidden sheets in a protected workbook
    By Balachan56 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 10-22-2009, 05:31 PM
  7. Able to access VB code on a protected workbook
    By KSP in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-30-2005, 11:05 AM

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