password protecting a macro

zilch4ry

Board Regular
Joined
Feb 27, 2011
Messages
76
Hi,

is there a way of protecting a macro button, so that it will not proceed unless the correct password has been entered?

Thanks in advance,
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Private Sub MacroNameHere_ActionHere()

pword = InputBox("Please Enter a Password", "Caption Here")
If pword = "12345" Then
Insert Code Here
Else
Exit Sub
End If
End Sub
 
Upvote 0
Thanks a lot for the help,
but how on earth do you put this into the macro code? i've pasted it onto the end of the macro but it just runs the macro without even using a password. Ive tried looking on google for advice on using private_sub but i cannot find anything on how you make them work.

This was my original code if it helps

Code:
Sub Input1()

Sheets("Input 1").Select

End Sub
 
Upvote 0
Assuming that you've created the buttom going to view/toolbars/forms
try like this:
In a module paste this code:
Code:
Sub Input1()
pword = InputBox("Please Enter a Password", "Caption Here")
If pword = "12345" Then
Sheets("Input 1").Select
Else
Exit Sub
End If
End Sub

Now go back and right click your button, choose "assign macro" select "Inputone"
you should now be OK
 
Upvote 0

Forum statistics

Threads
1,219,162
Messages
6,146,660
Members
450,706
Latest member
LGVBPP

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