June 26, 2016
Hello everyone My name is Maurizio and my problem is this:
Maybe I think to ask a question a little silly I have "stupid" that it is
But since I do not know the answer, I'll try with you.
My problem is this: Using a Userform I created a sort of Password Validation to protect a worksheet; And so far everything is OK
The problem, however, would be this: Since to call the userform I entered the code of opening within the procedure
(Worksheet_SelectionChange)
Silly wonder!
once the Password is found, the userform is rightly closed; For now at this point I would need a code that can tell the procedure (Worksheet_SelectionChange) no longer make me appear the userform until the application is restarted.
Do you think this opportunity exists?
Maybe using for example a code like this (Worksheet_SelectionChange = False)
(p.S) What would you do in my place Thanks
Greetings from A.Maurizio
VIP
Trusted Members
June 25, 2016
Hi Maurizio
I would have added a button on the sheet instead of asking user to select the cell.
Anyway you can try this code. It checks which cell was clicked and will display the form if cells E3 or E4 is selected.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("E3:E4")) Is Nothing Then
UserForm1.Show
End If
End Sub
Hope this helps.
Sunny
June 26, 2016
Hello SunnyKow How are you!
Listen Maybe the google translator did not express my words well; But I will try to explain myself better.
As you can see, my project works well in all its parts!
And it's a matter of protecting the Excel sheet; Here is the reason why I did not enter any key on the sheet itself, to open the userform.
That said, my question is as follows:
1 °) We hypothesize that you want to see my program with all the cells full of sensitive data; And let's assume that you want to please make some changes that I do not want to happen
There are two things: 1) I find the Password to unlock everything - 2) I have the userform will continue to ask you to enter a code three times and then automatically close the application
What I have not yet put into operation for "Praticita" of use being a test.
Ahora But if you find the way to enter by entering one of the four codes that I have made available; I would like that from then on, any changes I wanted to make to my worksheet can do so without appearing again my Userform Until the Application Restarted It's all here!
I hope I have been much clearer this time: Thanks for all the help you want to give me about it
Sincere greetings from A.Maurizio
VIP
Trusted Members
June 25, 2016
Hi Maurizio
I did not say I wanted to see your data. I just wanted to know what you want to achieve.
I was asking why you use a worksheet event instead of using a button (which in my opinion is easier to implement) to run the macro.
I am only guessing you want to allow only 3 tries to enter the password and if that fail then "lock" the application to prevent further tries.
The user will then need to close and reopen the file (restart?) to retry again. Is that what you wanted?
If that is the case I suggest you store a counter in one cell and check if the number of tries is less than 3 before displaying the userform.
Upon "restart" your macro (workbook open event) will need to reset the counter to 0.
Sunny
June 26, 2016
Hello SunnyKow listen to what I needed was simply this Code:
"Application.EnableEvents = False"
That works great; And I found it on a vba book I have in my bookshop.
That said, however, immediately discarded as it is never very clever to deactivate the functions of excel; Even itself and only a trial project.
So I finally adopted the simple Function (End) to close the userform in case the exact password is found here!
and the Code (Application.Quit) In case you exceed three attempts to enter.
And so far all Ok!
But now I do not know why but there is another problem here I can not give an answer, because I tried them all.
And the question is this:
Every time I enter an incorrect password and then I press the (OK) button the Textbox instead of zeroing and starting again from Zero; Continue from the Numbers I have previous letters:
Can you give me a look?
The codes to enter are written in the Help of the program itself. Thanks
For the rest everything works wonderfully Hello and Thanks
This is the link to download the whole again :
VIP
Trusted Members
June 25, 2016
Hi Maurizio
Yes, I know you will need to set Application.EnableEvents=False but I was trying to convince you not to use the Worksheet Events as they can get very messy if you are not careful. You will need to switch it off and on again in your codes.
Although you reset the Campo textbox to blank, you did not reset the Password variable and your code keeps on adding Password to the Campo text box.
In your Private Sub Cmd_Tasto_OK_Click() module you should add the line in red to reset the Password.
Tentativo = Tentativo + 1 'Aumenta di 1 il numero dei Tentativi
Campo.Text = ""
'Added by Sunny
Password = ""
Sunny
December 21, 2018
A.Maurizio said
That said, however, immediately discarded as it is never very clever to deactivate the functions of excel; Even itself and only a trial project.
Nothing wrong with application.enableevents=false as long as you have application.enableevents=true at the end of the code.
As previously stated, somewhere before focus on the textbox again, use password="" or campo.clear
June 26, 2016
Hi Dave Morrison Thanks for the advice I will take care of all this
But I managed to put all the pieces together and now my project Apportanto Substantial changes to make it work just as I wanted from the beginning
If you want, try it and let me know.
Clearly without many claims?
You all are undoubtedly better than me; Hello and thanks.
These are the links to Download the Modified Project and the complete List in the Text Document.
1) https://app.box.com/s/hh0lu07i.....5tqo65lh2c
2) https://app.box.com/s/csnj409p.....bgf0fk01lp
I offer this greetings to all of you and a warm thank you A.Maurizio
1 Guest(s)