Vba password prompt on Excel macro / password to restrict access to macros

dwilson38550m

Board Regular
Joined
Nov 21, 2005
Messages
89
Hi, I hope this is an easy one someone could help with - how do you put a password prompt in a macro so that it brings up a message box asking the user to enter a password before the macro runs successfully? Also is it possible to password restrict all macros so that no one came go in and alter the script/text - only you can see and edit with the password? Thanks in advance. David
 

Some videos you may like

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

mse330

Well-known Member
Joined
Oct 18, 2007
Messages
687
Office Version
365
Platform
Windows
You can use the below lines before your VBA code

Code:
Sub ABC()

Dim Pass As String
Pass = "Test"

If InputBox("Please enter the password to run the macro") <> Pass Then
    MsgBox "Incorrect password !", vbExclamation, "Error"
    Exit Sub
End If

'place your VBA code here

End Sub
To protect the VBE, click on Tools > VBA Project Properties > Protection > Password
 

Watch MrExcel Video

Forum statistics

Threads
1,102,633
Messages
5,488,017
Members
407,617
Latest member
Samanthad2007

This Week's Hot Topics

  • Timer in VBA - Stop, Start, Pause and Reset
    [CODE=vba][/CODE] Option Explicit Dim CmdStop As Boolean Dim Paused As Boolean Dim Start Dim TimerValue As Date Dim pausedTime As Date Sub...
  • how to updates multiple rows in muliselect listbox
    Hello everyone. I need help with below code. code is only chaning 1st row in mulitiselect list box. i know issue with code...
  • Delete Row from Table
    I am trying to delete a row from a table using VBA using a named range to find what I need to delete. My Range is finding the right cell. In the...
  • Assigning to a variable
    I have a for each block where I want to assign the value in column 5 of the found row to the variable Serv. [CODE=vba] For Each ws In...
  • Way to verify information
    Hi All, I don't know what to call this formula, and therefore can't search. I have a spreadsheet with information I want to reference...
  • Active Cell Address – Inactive Sheet
    How to use VBA to get the cell address of the active cell in an inactive worksheet and then place that cell address in a location on the current...
Top