+ Reply to Thread
Results 1 to 14 of 14

Password protect workbook on closure

  1. #1
    Registered User
    Join Date
    05-12-2019
    Location
    Sofia, Bulgaria
    MS-Off Ver
    2016
    Posts
    15

    Password protect workbook on closure

    Hi, found plenty material on how to auto protect with VBA all sheets in a workbook on closure of the latter, but no info on how to auto protect the workbook itself (structure and window). Any ideas?

  2. #2
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,728

    Re: Password protect workbook on closure

    https://docs.microsoft.com/en-us/off...rkbook.protect

    https://analysistabs.com/vba-code/workbook/m/protect/

    https://exceloffthegrid.com/vba-code...ect-workbooks/

    Just three that I found when I Googled "VBA protect workbook".
    Last edited by AliGW; 07-11-2019 at 05:15 PM.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  3. #3
    Registered User
    Join Date
    05-12-2019
    Location
    Sofia, Bulgaria
    MS-Off Ver
    2016
    Posts
    15

    Re: Password protect workbook on closure

    Just three that I found when I Googled "VBA protect workbook".[/QUOTE]


    This is very basic and I use it. My goal is to make the workbook protected om closing it, as I may forgot to do so before sending it to other people.

  4. #4
    Forum Contributor
    Join Date
    03-08-2018
    Location
    Denmark
    MS-Off Ver
    2016 for Windows
    Posts
    413

    Re: Password protect workbook on closure

    If it is to make sure that it protects, you will need the Workbook_BeforeClose Event.

    If you have a Macro called "Protect" to protect your workbook, then this should do it!

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-12-2019
    Location
    Sofia, Bulgaria
    MS-Off Ver
    2016
    Posts
    15

    Re: Password protect workbook on closure

    Thanks. Made the macro, placed your code in This workbook.. does wok. Dis you tried it?
    Last edited by AliGW; 07-13-2019 at 11:21 AM. Reason: Please don't quote unnecessarily!

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,728

    Re: Password protect workbook on closure

    Does or does not work? Please clarify.

  7. #7
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Password protect workbook on closure

    Something like this?

    In the ThisWorkbook module

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-12-2019
    Location
    Sofia, Bulgaria
    MS-Off Ver
    2016
    Posts
    15

    Re: Password protect workbook on closure

    At workbook closure I get the following message: Compile error! Procedure declaration does not match description of event or procedure having the same name.

  9. #9
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Password protect workbook on closure

    Place an example of your file with the code as you applied it.

  10. #10
    Registered User
    Join Date
    05-12-2019
    Location
    Sofia, Bulgaria
    MS-Off Ver
    2016
    Posts
    15

    Re: Password protect workbook on closure

    Attached sample
    Attached Files Attached Files

  11. #11
    Valued Forum Contributor
    Join Date
    04-01-2015
    Location
    The Netherlands
    MS-Off Ver
    2003/2007/2010/2016/office 365
    Posts
    880

    Re: Password protect workbook on closure

    Please Login or Register  to view this content.
    Attached Files Attached Files

  12. #12
    Registered User
    Join Date
    05-12-2019
    Location
    Sofia, Bulgaria
    MS-Off Ver
    2016
    Posts
    15

    Re: Password protect workbook on closure

    Thanks but this protects the worksheets (which I already figured out), but not the workbook (the subject of my post)
    Last edited by AliGW; 07-13-2019 at 12:40 PM. Reason: Please don't quote unnecessarily!

  13. #13
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,728

    Re: Password protect workbook on closure

    Administrative Note:

    Please don't quote whole posts, especially when you are responding to the one immediately preceding your own - it's just clutter. It's OK to quote if you are responding to a post out of sequence, but limit quoted content to a few relevant lines that makes clear to whom and what you are responding. Thanks!

    For normal conversational replies, try using the QUICK REPLY box below.

  14. #14
    Registered User
    Join Date
    05-12-2019
    Location
    Sofia, Bulgaria
    MS-Off Ver
    2016
    Posts
    15

    Re: Password protect workbook on closure

    Just to mention that the issue is still unresolved (does not work)... if somebody is confused by my typo in a previous post

+ 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: 11-17-2014, 04:28 PM
  2. Replies: 3
    Last Post: 07-01-2014, 02:48 PM
  3. Replies: 1
    Last Post: 04-12-2012, 03:42 AM
  4. Password protect workbook
    By edwedw in forum Excel General
    Replies: 3
    Last Post: 10-26-2010, 11:25 AM
  5. WorkBook Password Protect
    By rz6657 in forum Excel General
    Replies: 0
    Last Post: 09-27-2006, 09:44 PM
  6. [SOLVED] password protect workbook
    By rob in forum Excel General
    Replies: 1
    Last Post: 08-16-2006, 07:00 AM
  7. Replies: 2
    Last Post: 07-16-2005, 11:05 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