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
Any thoughts would be great!Please Login or Register to view this content.
Regards,
John
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
Any thoughts would be great!Please Login or Register to view this content.
Regards,
John
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.
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
Regards,Please Login or Register to view this content.
John
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
Hello
In standard module put this code
In another module test that codePlease Login or Register to view this content.
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
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.
Try this
Please Login or Register to view this content.
Something went wrong....
I added this before I saw your response
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 ProgramPlease Login or Register to view this content.
I don't understand what you're after ..
Hello,
This is the current code and not exactly where to place the suggested code
Current Code
What is recommended to be addedPlease Login or Register to view this content.
Regards,Please Login or Register to view this content.
John
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.
Hi Kev,
Tried your obviously uncomplicated suggestion but I still was able to use the Workbook in Read Only status.
Regards,
John
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
Ok... I will play with the settings and see how that plays out
Regards,
John
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.
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
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:
Then in the BeforeClose event macro set file back to ReadWritePlease Login or Register to view this content.
Please Login or Register to view this content.
Last edited by kev_; 08-25-2017 at 11:08 PM.
Hi Dev,
Thanks - I'll give it a look and try and let you know
Regards,
John
I'm just wondering why this portion of the code
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...Please Login or Register to view this content.
Currently the User if has entered the wrong password, can still interact with the workbook and this is not desired...
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 workbookPlease Login or Register to view this content.
Best Regards,
John
Last edited by JJFletcher; 08-25-2017 at 08:31 AM.
I will have brief access to a PC later today and see what I can come up with
Thanks Kev
Regards,
John
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.
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
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
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.
Last edited by kev_; 09-02-2017 at 02:45 AM.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks