+ Reply to Thread
Results 1 to 15 of 15

Protect Workbook with Password

  1. #1
    Registered User
    Join Date
    12-12-2016
    Location
    Newcastle Upon
    MS-Off Ver
    Ms Office 2010
    Posts
    64

    Post Protect Workbook with Password

    Hi Everyone,

    I am trying to save as new workbook with password. i have used below code to make it work but it's not working, as after running macro, the saved workbook can be opened with no password require.In another words how do i save the workbook with password protection when someone else try to open ? Any help will do

    i hope this makes sense

    Thank you


    Please Login or Register  to view this content.
    Last edited by 6StringJazzer; 12-21-2016 at 12:47 PM. Reason: code tags

  2. #2
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Protect Workbook with Password

    .
    .
    Using this code in a UserForm:

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

  3. #3
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Protect Workbook with Password

    Mouctar,

    when posting code, please use code tags, as per rule #3 on the forum rules.

    The protection you are using does not stop others from opening the workbook, it just prevents them from adding or removing sheets, or hiding/unhiding them.

    To password protect to open it, try:
    Please Login or Register  to view this content.
    Also some general advice: the whole point of using With... is to avoid having to type it again, so this:

    Please Login or Register  to view this content.
    would actually look like this:
    Please Login or Register  to view this content.
    Last edited by Arkadi; 12-21-2016 at 12:52 PM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Protect Workbook with Password

    Your code protects against changes to the file once it's opened but it does not prevent it from being opened. You want this:

    Please Login or Register  to view this content.
    Also, as noted, code tags are required. I added them for you since you are a new user but please read our rules.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Protect Workbook with Password

    Quote Originally Posted by Logit View Post
    .
    .
    Using this code in a UserForm:
    Unfortunately this method requires macros to be enabled. This can be defeated by simply turning off macros when opening the file.

  6. #6
    Registered User
    Join Date
    12-12-2016
    Location
    Newcastle Upon
    MS-Off Ver
    Ms Office 2010
    Posts
    64

    Re: Protect Workbook with Password

    Hi , Thank you for your help and i have tried this method and i am getting error. is there any other way to protect the workbook for not open without password please ?

  7. #7
    Forum Expert Logit's Avatar
    Join Date
    12-23-2012
    Location
    North Carolina
    MS-Off Ver
    Excel 2019 Professional Plus - 2007 Enterprise
    Posts
    7,014

    Re: Protect Workbook with Password

    Quote Originally Posted by 6StringJazzer View Post
    Unfortunately this method requires macros to be enabled. This can be defeated by simply turning off macros when opening the file.
    For most situations, it would work. Unfortunately there is no fool proof way of keeping anyone out of an Excel file.

  8. #8
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Protect Workbook with Password

    Did you try this version:

    Please Login or Register  to view this content.
    Last edited by Arkadi; 12-21-2016 at 04:07 PM.

  9. #9
    Registered User
    Join Date
    12-12-2016
    Location
    Newcastle Upon
    MS-Off Ver
    Ms Office 2010
    Posts
    64

    Re: Protect Workbook with Password

    Hi, Thank you for your help and i have tried your method but still not working as i can open the save workbook with no password required. Please see below full code and may be i have messed up the whole coding and if you don't mind tidy up please.

    Please Login or Register  to view this content.
    Last edited by Mouctar; 12-22-2016 at 09:14 AM.

  10. #10
    Forum Expert nigelog's Avatar
    Join Date
    12-14-2007
    Location
    Cork, Ireland
    MS-Off Ver
    Office 365 Windows 10
    Posts
    2,286

    Re: Protect Workbook with Password

    Mouctar - you will be asked to use code tags - look them up

  11. #11
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Protect Workbook with Password

    We provided two notices about this, so now I'm going to have to insist.

    Your post does not comply with Rule 3 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Click on Edit to open your thread, then highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found here

    (This thread should receive no further responses until this moderation request is fulfilled, as per Forum Rule 7)

  12. #12
    Registered User
    Join Date
    12-12-2016
    Location
    Newcastle Upon
    MS-Off Ver
    Ms Office 2010
    Posts
    64

    Re: Protect Workbook with Password

    Sorry, i have now amended and thank you for your help

  13. #13
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: Protect Workbook with Password

    Try changing this:
    Please Login or Register  to view this content.
    to this:
    Please Login or Register  to view this content.
    note that thiswb.path will not work because that only returns the directory the file is in, but not the actual file name, so it would give an error or just save it as the wrong name (adds .xlsm to the last part of the folder structure)
    Last edited by Arkadi; 12-22-2016 at 10:23 AM.

  14. #14
    Registered User
    Join Date
    12-12-2016
    Location
    Newcastle Upon
    MS-Off Ver
    Ms Office 2010
    Posts
    64

    Re: Protect Workbook with Password

    Hello! thank you so much and its now working. Much appreciated
    Another question!

    What is the correct code to send these workbooks as attachment to different recipients ?

    Thank you

  15. #15
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MO Prof Plus 2016
    Posts
    6,907

    Re: Protect Workbook with Password

    Another question!
    In that case please start another thread since your new question isn't in anyway related to this one.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

+ 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. Excel 2007 : Password protect workbook
    By shuddle in forum Excel General
    Replies: 2
    Last Post: 11-23-2011, 03:00 PM
  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

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