ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   HOW can I add a PASSWORD entry box to my Excel app using VBA? (https://www.excelbanter.com/excel-programming/285310-how-can-i-add-password-entry-box-my-excel-app-using-vba.html)

Marcello do Guzman

HOW can I add a PASSWORD entry box to my Excel app using VBA?
 
I have an application that I would like to add a password entry box.
The box would appear on the screen when a workbook is opened and the
user would have to enter a password to be able to use the workbook.
The password entry box would contain two buttons:

SUBMIT - Submits the password
CANCEL - This would close the workbook without saving.

The password would be written into the workbook (most likely in the
first spreadsheet) and the user would have to enter the password that
matches. If the password is incorrect then the workbook would display
a message box with a message like, "Sorry, but you have entered an
incorrect password. Please re-enter the correct password." The user
would be able to close this message box and try re-entering the
workbook.

I would be most grateful if you could let me know what VBA code I
would need to write to accomplish the above.

Please respond via email:

Thank you so much.

Marcello

Trevor Shuttleworth

HOW can I add a PASSWORD entry box to my Excel app using VBA?
 
Marcello

you've asked the same question three or four days in a row and had several
answers plus ideas that build on those answers. If you stayed in the same
thread people would know what works for you and what doesn't . You need to
explain what you've tried and why you still need other options.

Regards

Trevor


"Marcello do Guzman" wrote in message
...
I have an application that I would like to add a password entry box.
The box would appear on the screen when a workbook is opened and the
user would have to enter a password to be able to use the workbook.
The password entry box would contain two buttons:

SUBMIT - Submits the password
CANCEL - This would close the workbook without saving.

The password would be written into the workbook (most likely in the
first spreadsheet) and the user would have to enter the password that
matches. If the password is incorrect then the workbook would display
a message box with a message like, "Sorry, but you have entered an
incorrect password. Please re-enter the correct password." The user
would be able to close this message box and try re-entering the
workbook.

I would be most grateful if you could let me know what VBA code I
would need to write to accomplish the above.

Please respond via email:

Thank you so much.

Marcello




Pyball[_2_]

HOW can I add a PASSWORD entry box to my Excel app using VBA?
 
Marcello,

First you will have to create the userform with the buttons and
textboxes that you want. Then call the userform in the workbook_open
event.

Private Sub Workbook_Open()
UserFrom1.Show
End Sub

The code for the Submit button might look something like this:

Private Sub CommandButton1_Click()

Dim Str_Password As String

Str_Password = Sheets(1).Range("A1") 'You would of course have this
sheet hidden. You could also set the password here by replacing the
Sheets(1).Range("A1") with "Password", or what ever you select for the
password.

If TextBox1 = Str_Password Then
Unload Me
End If

If TextBox1 < Str_Password Then
Msgbox "Sorry, but you have entered an
incorrect password. Please re-enter the correct password.",vbOkayOnly +
vbCritical

TextBox1 = ""
TextBox1.SetFocus
Exit Sub
End If

End Sub

The code for the Cancel button might look something like this:

Private Sub CommandButton2_Click()

Application.DisplayAlerts = False
Application.Quit

End Sub

Hope this helps.


---
Message posted from http://www.ExcelForum.com/



All times are GMT +1. The time now is 08:16 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com