Password Protect Macro From Running

RichCowell

Board Regular
Joined
Dec 5, 2013
Messages
121
Office Version
  1. 365
Platform
  1. Windows
Hi,

I know it's possible to password protect Macros from viewing / editing the code, but is it possible to password protect them from running?

I've got two macros assigned to buttons, one to Protect all worksheets with a password, the other to unprotect them, with the password... But I'd like to prompt for one password before running the unprotect macro, so other users can't just click that to do them all... but I want it to be able to quickly edit it I need to without entering the password each time...
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try something like:

Code:
Sub test()
  Dim ans As String
  
  If Not Application.UserName = "My Name" Then
    ans = InputBox("What is the password?")
    
    If Not ans = "abc123" Then
      MsgBox "Incorrect password."
      Exit Sub
    End If
  End If
End Sub


Tim
 
Upvote 0
Try something like:

Code:
Sub test()
  Dim ans As String
  
  If Not Application.UserName = "My Name" Then
    ans = InputBox("What is the password?")
    
    If Not ans = "abc123" Then
      MsgBox "Incorrect password."
      Exit Sub
    End If
  End If
End Sub


Tim

Perfect!! Thanks! :-)
 
Upvote 0
Code:
Public Const PASSWORD As String = "12345" _
Function passwordmanager() As Boolean  
passwordmanager = PASSWORD = InputBox("Enter the Password", "Password")
End Function
Sub test()Do  
If passwordmanager() Then    
MsgBox "Correct Password"  
Else    
MsgBox "Incorrect Password"  
End If  
Loop Until passwordmanager = True
End Sub

Try this, I added a loop into this one so the person that tries to run it will have to end the program in task manager if he doesn't know the password :P
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,964
Members
452,371
Latest member
Frana

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