![]() |
Password Protecting a particular Sub
Hi All, I'm looking to put in some sort of protection that will require a password to run a particluar sub in an excel file. The sub will be attached to a button... I had thought that I should pop up an input box (somehow!) and then compare the input from the user to a defined constant in the code... is this the best way, and if so, how do I write the input box code? Here's the button code as it stands... it's nothing special! Private Sub CommandButton4_Click() Overduepdp ProtectSheet End Sub Thanks all. Gareth -- pianoman ------------------------------------------------------------------------ pianoman's Profile: http://www.excelforum.com/member.php...o&userid=33712 View this thread: http://www.excelforum.com/showthread...hreadid=544564 |
Password Protecting a particular Sub
Dim password As String Private Sub CommandButton4_Click() password = "clearannual" Set passwordinput = Application.InputBox(prompt:="Input Password to Clear Annual Dates", Type:=2) If passwordinput = password Then Overduepdp ProtectSheet Else response = MsgBox("Incorrect Password Supplied. Please try again", vbOKOnly, "Clear Annual dates Password") End If End Sub Obviously it's not working yet... -- pianoman ------------------------------------------------------------------------ pianoman's Profile: http://www.excelforum.com/member.php...o&userid=33712 View this thread: http://www.excelforum.com/showthread...hreadid=544564 |
Password Protecting a particular Sub
In its simplest form
Private Sub CommandButton4_Click() If InputBox("Password please:") < "Top Secret" Then Exit Sub Overduepdp ProtectSheet End Sub HTH. Best wishes Harald "pianoman" skrev i melding ... Hi All, I'm looking to put in some sort of protection that will require a password to run a particluar sub in an excel file. The sub will be attached to a button... I had thought that I should pop up an input box (somehow!) and then compare the input from the user to a defined constant in the code... is this the best way, and if so, how do I write the input box code? Here's the button code as it stands... it's nothing special! Private Sub CommandButton4_Click() Overduepdp ProtectSheet End Sub Thanks all. Gareth -- pianoman ------------------------------------------------------------------------ pianoman's Profile: http://www.excelforum.com/member.php...o&userid=33712 View this thread: http://www.excelforum.com/showthread...hreadid=544564 |
Password Protecting a particular Sub
Magic Harald, Works just fine. Many thanks, Gareth Harald Staff Wrote: In its simplest form Private Sub CommandButton4_Click() If InputBox("Password please:") < "Top Secret" Then Exit Sub Overduepdp ProtectSheet End Sub HTH. Best wishes Harald "pianoman" skrev i melding ... Hi All, I'm looking to put in some sort of protection that will require a password to run a particluar sub in an excel file. The sub will be attached to a button... I had thought that I should pop up an input box (somehow!) and then compare the input from the user to a defined constant in the code... is this the best way, and if so, how do I write the input box code? Here's the button code as it stands... it's nothing special! Private Sub CommandButton4_Click() Overduepdp ProtectSheet End Sub Thanks all. Gareth -- pianoman ------------------------------------------------------------------------ pianoman's Profile: http://www.excelforum.com/member.php...o&userid=33712 View this thread: http://www.excelforum.com/showthread...hreadid=544564 -- pianoman ------------------------------------------------------------------------ pianoman's Profile: http://www.excelforum.com/member.php...o&userid=33712 View this thread: http://www.excelforum.com/showthread...hreadid=544564 |
All times are GMT +1. The time now is 12:14 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com