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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().

BrianExcel

Well-known Member
Joined
Apr 21, 2010
Messages
969
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
 

zilch4ry

Board Regular
Joined
Feb 27, 2011
Messages
76
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
 

ndendrinos

Well-known Member
Joined
Jan 17, 2003
Messages
1,694
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
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,316
Messages
5,836,600
Members
430,441
Latest member
SurendraTantia

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
Top