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,
 

Some videos you may like

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.

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
 

Watch MrExcel Video

Forum statistics

Threads
1,122,514
Messages
5,596,609
Members
414,080
Latest member
penguin23

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