+ Reply to Thread
Results 1 to 26 of 26

Workbook Protection, delete all sheets if file name doesn’t match given name.

  1. #1
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148

    Workbook Protection, delete all sheets if file name doesn’t match given name.

    Hi all,

    I have a workbook which I’m happy with the levels of protection.
    For starters I have a ‘splash sheet’ which is the only sheet shown when opening the file.
    A box then pops up asking for a password (I’ve called it ‘Licence Key’). This password is located on a very hidden sheet that never pops up. If the password is correct they then get a message telling them how long the have (days) until it run out.
    The splash sheet then goes to very hidden and the other tabs appear.

    This all works great. However, I would like one more level of protection. I would like all the sheets to be deleted and only a splash sheet saying something like “This is a copied file” to remain. I will add the file name to the same sheet as the password (say “Sheet 1, Cell D5”

    Obviously this will mean that they can’t copy the file and paste in the same folder although they could copy it and paste it in another. This is something I haven’t figured out yet.

    Any advise? Macros or tips to help me with this would be great.

    Thanks

  2. #2
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,251

    Re: Workbook Protection, delete all sheets if file name doesn’t match given name.

    The mechanism could look like this:
    1. When you run the file for the first time, in a hidden sheet (or even in the system registry) save the path where the file is located (Thisworkbook.Path)
    2. During the next startups, check if the file location is the same as the saved one. If not, take drastic action.

    Artik

  3. #3
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148
    Quote Originally Posted by Artik View Post
    The mechanism could look like this:
    1. When you run the file for the first time, in a hidden sheet (or even in the system registry) save the path where the file is located (Thisworkbook.Path)
    2. During the next startups, check if the file location is the same as the saved one. If not, take drastic action.

    Artik
    That makes sense. So they can only save it once in one place. That’s a really good option. Obviously if they disable macros then this will just show the splash sheet but they could still get in my remove the project protection (if they could figure it out) but I plan on countering that by making some of the formulas incorrect on start up and having a marco change them. So they’ll need macros.

    Any clue on a macro for this protection?

    Thanks for the response and idea. It’s great.

  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,753

    Re: Workbook Protection, delete all sheets if file name doesn’t match given name.

    Care to share your project, suitably desensitized? I'm interested to see how easy it is to break into ... so no passwords needed.
    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


  5. #5
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148
    Quote Originally Posted by TMS View Post
    Care to share your project, suitably desensitized? I'm interested to see how easy it is to break into ... so no passwords needed.
    Hey TMS, yes I’d love you. Give me 5 mins and I’ll post it. Appreciate the help on this and any learning is good for me.

  6. #6
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148

    Re: Workbook Protection, delete all sheets if file name doesn’t match given name.

    @TMS, attached. I have removed all formulas. Please have a go and give me any feedback you have.

  7. #7
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148

    Re: Workbook Protection, delete all sheets if file name doesn’t match given name.

    File keeps failing to upload...... any ideas as to why?

  8. #8
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148

    Re: Workbook Protection, delete all sheets if file name doesn’t match given name.

    I've had to delete a lot of sheets as the files was huge.

    Thanks for the feedback..
    Attached Files Attached Files

  9. #9
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,251

    Re: Workbook Protection, delete all sheets if file name doesn’t match given name.

    Is your file larger than 1000 KB? Because this is the limitation of the forum. Are you following the yellow banner at the top of the page?

    ..::Edit
    The questions are no longer valid ::..

    Artik

  10. #10
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148
    Quote Originally Posted by Artik View Post
    Is your file larger than 1000 KB? Because this is the limitation of the forum. Are you following the yellow banner at the top of the page?

    Artik
    Yes it was 6.2MB, removed some tabs now and it’s on there.

    Thanks

  11. #11
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,251

    Re: Workbook Protection, delete all sheets if file name doesn’t match given name.

    Is the published project to be secured or should we break in?

    Artik

  12. #12
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148
    Quote Originally Posted by Artik View Post
    Is the published project to be secured or should we break in?

    Artik
    You can break it.

  13. #13
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,251

    Re: Workbook Protection, delete all sheets if file name doesn’t match given name.

    I've already done that.

    Artik

  14. #14
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148
    Quote Originally Posted by Artik View Post
    I've already done that.

    Artik
    Okay, I thought you would. I know nothing is 100% secure but what else can I do to protect it? You can’t see it because I’ve removed all the sheets and formulas but I’ve put a lot of effort in and I want to make it so people can only get a copy from me for a set time frame.

    Ideally this would happen

    - they get a copy of the workbook that can’t be copied
    - they have a set time frame to complete it
    - after that time frame all the formulas are removed
    - all sheets are then Unlocked
    - the parameters tab and splash sheet are deleted
    - the macros are removed (not that important)
    - the file then save as an excel workbook (not macro enable)

    Then they are left with the result of their work but can’t use it again.

  15. #15
    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,753

    Re: Workbook Protection, delete all sheets if file name doesn’t match given name.

    No break in (strictly) required.

    Licence Holder: Kevin Rush Access Start Date: 28/03/2022
    Licence Password: 2807 Access Days: 2
    Access Key Holder: TMS Access Expiry Date: 30/03/2022
    Access Key: PASSTMS Protect Cell Password: 2807


  16. #16
    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,753

    Re: Workbook Protection, delete all sheets if file name doesn’t match given name.

    And

    ?wb.name
    TMS - MasterKey.xlsm
    Macros
    PARAMETERS
    MENU
    Tank Data & Service Details
    Shell Assessment - Product SG
    Shell Assessment - Hydro Test

    When I cancelled the password box, it showed the sheets anyway (but not PARAMETERS)

  17. #17
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148

    Re: Workbook Protection, delete all sheets if file name doesn’t match given name.

    So not to hard then?

    If you cancel the password box only the slash sheet should be visible…??

  18. #18
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148

    Re: Workbook Protection, delete all sheets if file name doesn’t match given name.

    In fact, when you cancel the Password box it should close the file?

  19. #19
    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,753

    Re: Workbook Protection, delete all sheets if file name doesn’t match given name.

    Yes, not too hard but I can't explain in the thread because, effectively, it is bypassing YOUR security.

    Bed time. Talk tomorrow.

  20. #20
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148

    Re: Workbook Protection, delete all sheets if file name doesn’t match given name.

    When I cancel the password box it say “this key has not been issued” and makes you close the file, which a save option.

    Okay, let me know when you have change to explain. Thanks again.

  21. #21
    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,753

    Re: Workbook Protection, delete all sheets if file name doesn’t match given name.

    When I cancel the password box it say “this key has not been issued” and makes you close the file, which a save option.
    Yes, it does do that. Not sure quite how I managed to open it without providing the Pass Key. I don't seem to be able to replicate whatever I did.

    (PM) Thanks, so essentially. It was easy to search for the password. I Can sort that. Do you think for an intermedaite that this is a fairly secure workbook?
    Yes, it seems to be a good implementation of the Splash Screen approach. Always a pain to set up and cover all the options. The only thing I don't like is that, if it is the only workbook open, when it closes it doesn't close Excel. You could check the number of workbooks open and, if it is one, shut the application down.

    (PM) Thanks. Do you think is could be any more secure just by using VBA?
    Excel is, historically, not a secure environment, although I think a lot of the loopholes have been closed. I think, as it stands, it has a good level of security. It should stop the majority of day-to-day Excel users, and even some of the more advanced one.

    I don't think you really need to change anything dramatically. As I explained, there are ways of accessing the data without having the password. It's easy enough to make the sheets visible, but you have covered that by locking, hiding the formulae, and setting the font to white before protecting the sheet. That can't be changed without unprotecting the sheet.


    With regard to your original question, I'm not sure how big a risk you think this is. It could p!$$ people off big time if they've spent time on the workbook and want to save/copy it to take it home to carry on in the evening, only to find their efforts (at least on the copy) have been destroyed.

    Even locking the workbook to a folder, drive, or machine could be restrictive and frustrating.

    I have created "time-bombed" workbooks in the past but, if I'm honest, I'm not happy about it.

  22. #22
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148

    Re: Workbook Protection, delete all sheets if file name doesn’t match given name.

    Firstly, thank you for your time and explanation, it's given me a level of confidence in my protection. I actually agree with the fact that locking them out past the date is probably extreme. That's why I've been thinking of just removing the formulas and deleting the parameters sheet. Problem with that is that is where the passwords are so i would also have to removed that macro. So essentially, once past the date it just turns into a workbook with data. If thats possible.

    Thanks again, if i remember correctly this isn't the 1st time you've helped me.

  23. #23
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,251

    Re: Workbook Protection, delete all sheets if file name doesn’t match given name.

    For several years, by default, files downloaded from the Internet (www or e-mail) receive the MOTW (Mark of the Web) attribute. After opening the file in Excel, a message asking for permission to open the file appears in the yellow bar. Expressing consent removes the MOTW attribute. The file initially opened in Protected View is reopened in "Normal Mode". At this point, when the Workbook_Open event is programmed, an error may occur because the engine does not "see" the properties and methods of the application yet. This is an issue that has been confirmed by MS. Therefore, it is recommended to use a structure similar to the following. Suppose we originally had a procedure:
    Please Login or Register  to view this content.
    After the change, it should look like this:
    Please Login or Register  to view this content.
    In my opinion, the order of calling procedures in Workbook_Open should be different. First OpenBook, then ShowAllSheets. It will probably require some other minor changes. I can't understand why if you enter the wrong password (or press Cancel) you are asking the user to save the changes. A bad password is to close the file without saving your changes (and without asking). In addition, I believe that the data in the PARAMETERS!I2:L5 range should be encrypted (not only columns J and L, but also I and K) in order not to give the burglar everything on the tray.
    Quote Originally Posted by Kevin Rush View Post
    That's why I've been thinking of just removing the formulas and deleting the parameters sheet. Problem with that is that is where the passwords are so i would also have to removed that macro.
    You can replace formulas with values by looping through all sheets and by looping through all cells containing formulas. Or, if the formulas are in continuous ranges,
    Please Login or Register  to view this content.
    After all the destructive activity, save the file as XLSX. And an XLSM file should commit suicide.
    Please Login or Register  to view this content.
    Artik

  24. #24
    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,753

    Re: Workbook Protection, delete all sheets if file name doesn’t match given name.

    You're welcome. Thanks for the rep.


    Never been one for using macros to delete macros. I would have thought converting all the sheets to values, and deleting the splash screen and menu sheets might come close. Oh, and don't hide/unhide anything. That's just a check in the Open and Close macros.

    If there's nothing to call the macros, they can just lay there hidden and dormant.

  25. #25
    Forum Contributor
    Join Date
    09-25-2018
    Location
    Grimsby, UK
    MS-Off Ver
    365
    Posts
    148
    Quote Originally Posted by Artik View Post
    For several years, by default, files downloaded from the Internet (www or e-mail) receive the MOTW (Mark of the Web) attribute. After opening the file in Excel, a message asking for permission to open the file appears in the yellow bar. Expressing consent removes the MOTW attribute. The file initially opened in Protected View is reopened in "Normal Mode". At this point, when the Workbook_Open event is programmed, an error may occur because the engine does not "see" the properties and methods of the application yet. This is an issue that has been confirmed by MS. Therefore, it is recommended to use a structure similar to the following. Suppose we originally had a procedure:
    Please Login or Register  to view this content.
    After the change, it should look like this:
    Please Login or Register  to view this content.
    In my opinion, the order of calling procedures in Workbook_Open should be different. First OpenBook, then ShowAllSheets. It will probably require some other minor changes. I can't understand why if you enter the wrong password (or press Cancel) you are asking the user to save the changes. A bad password is to close the file without saving your changes (and without asking). In addition, I believe that the data in the PARAMETERS!I2:L5 range should be encrypted (not only columns J and L, but also I and K) in order not to give the burglar everything on the tray.
    You can replace formulas with values by looping through all sheets and by looping through all cells containing formulas. Or, if the formulas are in continuous ranges,
    Please Login or Register  to view this content.
    After all the destructive activity, save the file as XLSX. And an XLSM file should commit suicide.
    Please Login or Register  to view this content.
    Artik
    Thanks,

    I have a macro that removes all the formulas, so I can just call that macro.
    The. I would then need the file to save as XLSX. Following that I need the ‘suicide’.

    I will try this now.

  26. #26
    Forum Expert
    Join Date
    08-17-2007
    Location
    Poland
    Posts
    2,251

    Re: Workbook Protection, delete all sheets if file name doesn’t match given name.

    Quote Originally Posted by TMS View Post
    Never been one for using macros to delete macros.
    Deleting code with a macro is riddled with great reefs. Programmatic access to the project must be enabled, which is disabled by default. You cannot remove code from a module where the macro is currently executing. And if that wasn't enough, there are big problems with programmatic unlocking of project. Therefore, it is much easier to save the file as XLSX.

    Artik

+ 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. Replies: 2
    Last Post: 10-25-2021, 02:37 AM
  2. Password Protection to delete file or Folder
    By Ratna K. Sthapit in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-11-2014, 03:14 PM
  3. Password Protection to delete file or Folder
    By Ratna K. Sthapit in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-11-2014, 10:23 AM
  4. Replies: 2
    Last Post: 06-28-2010, 05:26 PM
  5. Split Workbook with Many Sheets into a file for each Worksheet and delete all others
    By Please_Help in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-19-2010, 07:31 PM
  6. Replies: 2
    Last Post: 12-12-2005, 02:40 PM
  7. Workbook/sheet protection doesn't seem to work
    By Mark Stephens in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 06-11-2005, 07:05 PM

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