+ Reply to Thread
Results 1 to 12 of 12

Protect workbook for UserInterfaceOnly

  1. #1
    Registered User
    Join Date
    07-24-2015
    Location
    Toledo, OH
    MS-Off Ver
    Microsoft Office 2010
    Posts
    85

    Protect workbook for UserInterfaceOnly

    Hi all,

    From what I've seen online so far, there is no workaround for my problem, so this is my final desperate attempt to find an answer.

    Over the past three months, I have been building a database in Excel. It is very complex and extensive at this point. I've put in various layers of simple protection, like password-protecting the individual worksheets, protecting the VBA project code, hiding all inactive sheets automatically, and building a login userform with different levels of access. Everything works very nicely, and I'm pleased with how it has turned out.

    It occurred to me yesterday that I should probably find a way to prevent users from adding new worksheets to the database. This is mainly because it would seriously jack up the login code if they did add one. There aren't any people in my workplace who would deliberately try to mess things up, but there are plenty of people here who would mess things up accidentally, and I figured preventing worksheet additions would be another ounce of idiot-proofing.

    Here's the problem: if I set up the basic Workbook.Protect method in the Workbook Open event, a whole ton of other code gets messed up. For example, every time the VBA tries to unhide or hide a sheet, the code crashes. Yes, I could go through and lift the workbook protection whenever a sheet needs to be hidden or un-hidden, but we are talking thousands of lines of code, and it would take me a million years, and I'd probably miss a few points where I should have added it and then the code will crash on a user, which is a very bad thing.

    Is there any way to set up Workbook Protect so it protects from user interface only? I know I can protect the worksheets this way. This would be a lovely workaround for me. However, from what I've seen online, this isn't possible. PLEASE tell me there is a workaround! I really don't want to have to sit down and go through all the work of protecting and unprotecting on each macro, and I also really don't want users to be able to accidentally add worksheets. For heaven's sake, I accidentally added one the other day! I deleted it immediately, but you can't assume that a user would be sensible enough to do that.

    If there isn't a workaround, I'll go through and add the protection and unprotection everywhere. But it would be nice if one of you could save me from that.

  2. #2
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,357

    Re: Protect workbook for UserInterfaceOnly

    See this for a very clear description: http://www.cpearson.com/excel/Protection.aspx

    I would have thought that if you protect the workbook structure and windows, the user wouldn't see the options to create and delete sheets, or at least they'd be greyed out. So that shouldn't be an issue.


    Regards, TMS
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  3. #3
    Registered User
    Join Date
    07-24-2015
    Location
    Toledo, OH
    MS-Off Ver
    Microsoft Office 2010
    Posts
    85

    Re: Protect workbook for UserInterfaceOnly

    I was already aware of this page; it was what gave me the idea of using Workbook.Protect in the first place. And the Workbook.Protect does do exactly what it says: it prevents users from adding, deleting or moving sheets. The problem is that a lot of my current code will hide or un-hide various worksheets as part of the process, and apparently that counts as moving a worksheet because if I set Workbook.Protect, the macros crash. That was the whole problem: I'm looking for another way to do this that won't mess up my current code.

  4. #4
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,357

    Re: Protect workbook for UserInterfaceOnly

    Ah, fair enough. I can't help then, sorry. I must admit to rarely, if ever, using UserInterfaceOnly preferring to use UnProtect ... do something ... Protect again.

    But, in reality, you could use UserInterfaceOnly to cater for the changes you make on the worksheet(s) and just UnProtect and Protect the workbook when you want to hide stuff.

    Regards, TMS

  5. #5
    Registered User
    Join Date
    07-24-2015
    Location
    Toledo, OH
    MS-Off Ver
    Microsoft Office 2010
    Posts
    85

    Re: Protect workbook for UserInterfaceOnly

    I'm probably going to end up doing exactly that. The problem is that means I now have to go through about eighty thousand lines of code and remove all the protect and unprotect stuff. Sigh.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,357

    Re: Protect workbook for UserInterfaceOnly

    about eighty thousand lines of code
    Not structured then?

  7. #7
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,357

    Re: Protect workbook for UserInterfaceOnly

    I guess you could work through each module, assuming there are more than one module, using "Find" to locate ".Visible". The dialogue will remain open whilst allowing you to edit the code so you can use "Find Next" to progress through the module. Bit trial and error but better than visually scanning.

    Regards, TMS

  8. #8
    Registered User
    Join Date
    07-24-2015
    Location
    Toledo, OH
    MS-Off Ver
    Microsoft Office 2010
    Posts
    85

    Re: Protect workbook for UserInterfaceOnly

    Oh, no, it's all structured and very neat. There's just a whole lot of it. We're talking over twenty userforms alone, let alone modules and all the code attached to each worksheet.

    I'm going through it one window at a time. It's probably not a bad thing that I'm re-reading all of the code. I can check the formatting and make sure I have titles on all of my message boxes, and stuff like that.

  9. #9
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,357

    Re: Protect workbook for UserInterfaceOnly

    Every cloud ...




    If you are satisfied with the solution(s) provided, please mark your thread as Solved.


    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:

    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save


    You may also want to consider thanking those people who helped you by clicking on the little star at the bottom left of their reply to your question.

  10. #10
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    44,357

    Re: Protect workbook for UserInterfaceOnly

    One thought: if you search for every occurrence of "visible", you could change that line to call a subroutine. Pass the subroutine True or False. Then the subroutine can include the Unprotect or Protect and the Visible parameter. You don't increase the number of lines of code and you put the work in the subroutine. Any lines in the main body of code MUST have been overlooked.

    Regards, TMS

  11. #11
    Registered User
    Join Date
    07-24-2015
    Location
    Toledo, OH
    MS-Off Ver
    Microsoft Office 2010
    Posts
    85

    Re: Protect workbook for UserInterfaceOnly

    I think I'm just going to go through it manually. I'm already halfway through it now, and I've only been at it for half an hour, so it won't be as bad as I thought. Thanks!

  12. #12
    Registered User
    Join Date
    11-22-2017
    Location
    PHILIPPINES
    MS-Off Ver
    2016
    Posts
    1
    Quote Originally Posted by TMS View Post
    Ah, fair enough. I can't help then, sorry. I must admit to rarely, if ever, using UserInterfaceOnly preferring to use UnProtect ... do something ... Protect again.

    But, in reality, you could use UserInterfaceOnly to cater for the changes you make on the worksheet(s) and just UnProtect and Protect the workbook when you want to hide stuff.

    Regards, TMS
    This subject still not solve... We create forms and protect workbook so that the macros can do the hide and hiding while the users cannot accidentally move the sheet or hide them..

    With your suggestion to manually protect the wb it takes away the concept of the user and admin.

+ 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] How do I turn on Protection UserInterFaceOnly on a shared workbook?
    By scottbass in forum Excel General
    Replies: 5
    Last Post: 01-12-2014, 06:52 PM
  2. Sheets.Protect UserInterfaceOnly parm not working for me
    By Weebie in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-17-2007, 05:42 PM
  3. .protect userinterfaceonly:=true not working?
    By dreamz in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-20-2006, 07:31 PM
  4. ".Protect userinterfaceonly:=True" & ".EnableSelection = xlUnlockedCells" not tabing
    By STEVE BELL in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-22-2006, 09:40 PM
  5. How to protect desired area of workbook and protect code.
    By avveerkar in forum Excel General
    Replies: 4
    Last Post: 01-12-2006, 10:44 PM
  6. [SOLVED] Passwords Disappear in OpenOffice (Protect Worksheet, and Protect Workbook)
    By msnews.microsoft.com in forum Excel General
    Replies: 6
    Last Post: 12-27-2005, 04:20 AM
  7. Replies: 2
    Last Post: 07-16-2005, 11:05 AM
  8. Protect UserInterfaceOnly + Control deletion of file in same folder
    By Alex Hatzisavas in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-31-2005, 07:02 AM

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