Require a password in order to click a button on userform VBA

Haikal

New Member
Joined
Jan 16, 2014
Messages
28
I have a userform, and i applied the following in order to run the userform without showing the sheet
Code:
<code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(238, 238, 238); font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: inherit; background-position: initial initial; background-repeat: initial initial; ">[COLOR=#00008B]Private[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]Sub[/COLOR][COLOR=#000000] Workbook_Open[/COLOR][COLOR=#000000]()[/COLOR][COLOR=#000000]    Application[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Visible [/COLOR][COLOR=#000000]=[/COLOR][COLOR=#000000] [/COLOR][COLOR=#800000]False[/COLOR][COLOR=#000000]    UserForm1[/COLOR][COLOR=#000000].[/COLOR][COLOR=#000000]Show vbModeless[/COLOR][COLOR=#00008B]End[/COLOR][COLOR=#000000] [/COLOR][COLOR=#00008B]Sub[/COLOR]</code></pre>
i need to add a button in the userform that enables me to open the sheet to edit it. and set a password so as no one can open it except me.
i.e. when clicking "Button1", a popup message requiring a password, and if the password is incorrect, it return a msg like "Wrong password", if the password is correct -->
Code:
<code style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 1px; padding-right: 5px; padding-bottom: 1px; padding-left: 5px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; font-size: 14px; vertical-align: baseline; background-image: initial; background-attachment: initial; background-origin: initial; background-clip: initial; background-color: rgb(238, 238, 238); font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif; white-space: pre-wrap; background-position: initial initial; background-repeat: initial initial; ">Application.Visible = true</code>
Many thanks
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Hi Haikal,

Is something like this what you're after?

Code:
Private Sub CommandButton1_Click()
Dim MyValue As Variant
MyValue = InputBox("Enter Password")
If MyValue = "lemonade" Then 'lemonade being the password
Application.Visible = True
Else
MsgBox ("Password Incorrect")
End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,222
Messages
6,129,588
Members
449,520
Latest member
TBFrieds

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top