+ Reply to Thread
Results 1 to 26 of 26

How to mask the password using this code

  1. #1
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    985

    How to mask the password using this code

    Hello Everyone,

    I have this code that is used when the workbook opens and I would like to have it masked - right now it shows the word being entered

    Please Login or Register  to view this content.
    Any thoughts would be great!

    Regards,

    John

  2. #2
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to mask the password using this code

    Hi,

    It's much easier to use a userform and textbox. If you want to use Inputbox, you must use API functions like this- http://www.ozgrid.com/forum/showthread.php?t=72794
    Don
    Please remember to mark your thread 'Solved' when appropriate.

  3. #3
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    985

    Re: How to mask the password using this code

    Thanks so much for the feed back...

    The part that is missing in using a Form for the Password is the Read Only attribute that is available in this code

    Please Login or Register  to view this content.
    Regards,

    John

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: How to mask the password using this code

    Cannot do it with input box
    Use text box in user form with PasswordChar set to *

    TextBoxWithPassword.jpg
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  5. #5
    Forum Guru xlnitwit's Avatar
    Join Date
    06-27-2016
    Location
    London
    MS-Off Ver
    Windows: 2010; Mac: 16.13 (O365)
    Posts
    7,085

    Re: How to mask the password using this code

    Quote Originally Posted by JJFletcher View Post
    Thanks so much for the feed back...

    The part that is missing in using a Form for the Password is the Read Only attribute that is available in this code

    Please Login or Register  to view this content.
    Regards,

    John
    I'm afraid I don't understand. The userform works exactly like the inputbox so I don't see what the problem with the remaining code could be?

  6. #6
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: How to mask the password using this code

    Hello
    In standard module put this code
    Please Login or Register  to view this content.
    In another module test that code
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  7. #7
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    985

    Re: How to mask the password using this code

    HI YasserKhalil,

    I have put the code above in the workbook and it functions as it should except if the user enters the wrong password - they have a few more chances and then says "Incorrect Password Entered Too Many Times. Try Again Later".... Rather then try again later I would like the user to be able to use the workbook but with "Read Only" privileges.. Can that be added to this code supplied by you?

    Regards,

    John
    Last edited by JJFletcher; 08-23-2017 at 08:02 AM.

  8. #8
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: How to mask the password using this code

    Try this
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    985

    Re: How to mask the password using this code

    Something went wrong....


    I added this before I saw your response

    Please Login or Register  to view this content.
    Now the workbook won't open to let me correct the code I get this when trying to launch" Microsoft Excel has stopped working Restart Program

  10. #10
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: How to mask the password using this code

    I don't understand what you're after ..

  11. #11
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    985

    Re: How to mask the password using this code

    Hello,

    This is the current code and not exactly where to place the suggested code

    Current Code
    Please Login or Register  to view this content.
    What is recommended to be added
    Please Login or Register  to view this content.
    Regards,

    John

  12. #12
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: How to mask the password using this code

    What you are trying to do seems unnecessarily complicated
    - especially when Excel offers this option free of charge

    Saving the file with Password required to MODIFY the file but allowing it to be opened "read only" by anyone,
    also masks the words entered
    (seems to meet everything requested in post#1)

    SaveAs\Tools\General Options


    OpenReadOnly.jpg
    Last edited by kev_; 08-24-2017 at 03:57 AM.

  13. #13
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    985

    Re: How to mask the password using this code

    Hi Kev,

    Tried your obviously uncomplicated suggestion but I still was able to use the Workbook in Read Only status.

    Regards,

    John

  14. #14
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: How to mask the password using this code

    Read and play yes, but cannot not save any modifications.

    1 Save the file with relevant worksheets protected as default
    (Protection is very flexible)
    2. User opens file
    - read-only : leave protection in place
    - with password : lift sheet protection allowing user to modify

    Control via VBA

  15. #15
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    985

    Re: How to mask the password using this code

    Ok... I will play with the settings and see how that plays out

    Regards,

    John

  16. #16
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: How to mask the password using this code

    I am away from my PC for several days and so cannot test, but I think this will allow you to distinguish between user who used a password and one who did not .

    In the ThisWorkbook module
    Please Login or Register  to view this content.

  17. #17
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    985

    Re: How to mask the password using this code

    Hi Kev...

    I think your code is great and I appreciate the help... I am wondering however is the original code which works great to provide the masking **** able to have this attribute written there - this way the call to the module will be singular and not require as many steps

    Regards,

    John

  18. #18
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: How to mask the password using this code

    You could try:
    Open file normally with no password required
    Ask user for password with VBA
    (With userform to allow masking)
    Change file attribute if user fails to give password
    Change file attribute back again when user closes file
    Something like:
    Please Login or Register  to view this content.
    Then in the BeforeClose event macro set file back to ReadWrite
    Please Login or Register  to view this content.
    Last edited by kev_; 08-25-2017 at 11:08 PM.

  19. #19
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    985

    Re: How to mask the password using this code

    Hi Dev,

    Thanks - I'll give it a look and try and let you know

    Regards,

    John

  20. #20
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    985

    Re: How to mask the password using this code

    I'm just wondering why this portion of the code

    Please Login or Register  to view this content.
    that sets the workbook to Read Only cannot be placed into the Test Module somehow insuring that if the User fails entering the Password correctly that the entire workbook is Read Only...

    Currently the User if has entered the wrong password, can still interact with the workbook and this is not desired...

    Please Login or Register  to view this content.
    This current code shuts down the workbook after 3 failed attempts... I do not want the workbook to close but be in a Read Only state and allow the user to view the workbook but not use the workbook to modify the workbook

    Best Regards,

    John
    Last edited by JJFletcher; 08-25-2017 at 08:31 AM.

  21. #21
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: How to mask the password using this code

    I will have brief access to a PC later today and see what I can come up with

  22. #22
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    985

    Re: How to mask the password using this code

    Thanks Kev



    Regards,

    John

  23. #23
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: How to mask the password using this code

    Everything is being typed in manually, so apologies for any typos not spotted...
    I could attach a file containing the working code on Tuesday - if that would be helpful let me know

    This method works for me and is simple:

    1. The workbook does not require password protection
    2. When file is opened, a macro is called asking user for password
    3. If user fails to provide password then file is set to ReadOnly (to prevent user saving the file) and sheets are protected (so that no cells can be selected) - stopping user interaction with workbook but allowing user to see contents
    4. There is a further macro to prevent the file being saved under a different name
    5. If user provides correct password, happy days - normal user action permitted

    It would be easiest if all VBA is placed in ThisWorkbook module:
    Please Login or Register  to view this content.
    Last edited by kev_; 08-26-2017 at 02:00 AM.

  24. #24
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: How to mask the password using this code

    I will post a file on Tuesday which combines everything in post#23 with a userform to give you the requested masking
    - too painful and error-prone re-typing all the code

  25. #25
    Forum Contributor
    Join Date
    09-10-2008
    Location
    Phoenix, AZ
    MS-Off Ver
    Office 365
    Posts
    985

    Re: How to mask the password using this code

    Hi Kev,

    Thanks so much... I will be looking forward to seeing the file next week... in the mean time, I will begin to integrate the above code...

    Regards,

    John
    Last edited by JJFletcher; 08-26-2017 at 11:44 AM. Reason: Grammer

  26. #26
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: How to mask the password using this code

    With Userform Password Masking

    I have now moved from Windows 7 to Windows 10 as a result of my PC's untimely death
    For some reason which I cannot fathom, Excel's behaviour appears to have changed in a couple of areas - it could simply be a setting , but have not had time to investigate
    One line that refuses to "play ball" is the one setting the file to xlReadOnly -it could be something to do with how autosave is working on my new laptop which appears to be much more bossy

    So the workaround is simply to rely on protecting all worksheets to prevent the user (with incorrect password) selecting or changing anything - it's crude but it appears to work. Try it in the attached file.

    The userform is called when the workbook is opened
    - if password correct all sheets unproteced
    - 3 chances for user to provide correct password
    - after 3 failures sheets are protected and the user can wander around the workbook but cannot change anything

    Although user clicks on OK button, there is no code behind the button - clicking on it triggers the "Exit" event
    The userform consists
    - a textbox with PasswordChar set to *
    - a label to communicate with user after 1st unsuccessful attempt
    - OK button

    Userform code is simply:
    Please Login or Register  to view this content.

    The userform calls these procedures which are also in the Userform module:

    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by kev_; 09-02-2017 at 02:45 AM.

+ 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. How to Mask Password in MsgBox ???
    By JJFletcher in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 05-06-2016, 09:38 PM
  2. *** mask password in inputbox
    By Kvracing in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 02-05-2015, 08:16 PM
  3. *** mask password in inputbox
    By Kvracing in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-14-2014, 07:55 PM
  4. Hide/Mask Cell Data Unless Password Entered
    By JimmyG. in forum Excel General
    Replies: 1
    Last Post: 06-28-2014, 04:16 PM
  5. VBA code that bypass Password prompt for every workbook with one master password
    By pwnyadav007 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-22-2014, 01:45 AM
  6. Password removal via VBA (as defined in the code with password)
    By galvinpaddy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-22-2013, 07:35 AM
  7. Can't pass password through code, keeps prompting for password
    By Alexander40 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-20-2012, 03:55 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