Skip to content
Free Excel Tutorials
  • Home
  • Excel For Beginners
  • Excel Intermediate
  • Advanced Excel For Experts

Data Analysis

  • Get column index in Excel Table
  • Understanding Pivot Tables in Excel
  • Everything about Charts in Excel
  • Subtotal function in Excel
  • How to combine 2 or more chart types in a single chart in Excel

References

  • How to use Excel FORMULATEXT function
  • How to get address of last cell in range in Excel
  • How to use Excel MMULT Function
  • How to get last column number in range in Excel
  • Multi-criteria lookup and transpose in Excel

Data Validations

  • Excel Data validation date in specific year
  • Excel Data validation number multiple 100
  • Excel Data validation allow weekday only
  • Prevent invalid data entering in specific cells
  • Excel Data validation date in next 30 days

Password Protect Macro in Excel

by

Just like you can password protect workbooks and worksheets, you can password protect a macro in Excel from being viewed (and executed).

Place a command button on your worksheet and add the following code lines:

1. First, create a simple macro that you want to protect.

Range(“A1”).Value = “This is secret code”

2. Next, click Tools, VBAProject Properties.

3. On the Protection tab, check “Lock project for viewing” and enter a password twice.

4. Click OK.

5. Save, close and reopen the Excel file. Try to view the code.

The following dialog box will appear:

You can still execute the code by clicking on the command button but you cannot view or edit the code anymore (unless you know the password). The password for the downloadable Excel file is “easy”.

6. If you want to password protect the macro from being executed, add the following code lines:

Dim password As Variant
password = Application.InputBox("Enter Password", "Password Protected")Select Case password
Case Is = False
'do nothing
Case Is = "easy"
Range("A1").Value = "This is secret code"
Case Else
MsgBox "Incorrect Password"
End Select

Result when you click the command button on the sheet:

Explanation: The macro uses the InputBox method of the Application object. If the users clicks Cancel, this method returns False and nothing happens (InputBox disappears). Only when the user knows the password (“easy” again), the secret code will be executed. If the entered password is incorrect, a MsgBox is displayed. Note that the user cannot take a look at the password in the Visual Basic Editor because the project is protected from being viewed.

Post navigation

Previous Post:

VLOOKUP without #N/A error in Excel

Next Post:

Manipulating text strings using Left, Mid, Right, Len, Substitute in Excel

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Learn Basic Excel

Ribbon
Workbook
Worksheets
Format Cells
Find & Select
Sort & Filter
Templates
Print
Share
Protect
Keyboard Shortcuts

Categories

  • Charts
  • Data Analysis
  • Data Validation
  • Excel Functions
    • Cube Functions
    • Database Functions
    • Date and Time Functions
    • Engineering Functions
    • Financial Functions
    • Information Functions
    • Logical Functions
    • Lookup and Reference Functions
    • Math and Trig Functions
    • Statistical Functions
    • Text Functions
    • Web Functions
  • Excel VBA
  • Excel Video Tutorials
  • Formatting
  • Grouping
  • Others

Logical Functions

  • Nested IF function example in Excel
  • NOT function: Description, Usage, Syntax, Examples and Explanation
  • Return blank if in Excel
  • Check multiple cells are equal in Excel
  • How to use Excel OR Function

Date Time

  • Convert time to time zone in Excel
  • Assign points based on late time in Excel
  • Get week number from date in Excel
  • How to calculate working days left in month in Excel
  • Calculate series of dates by workdays in Excel

Grouping

  • Group times into 3 hour buckets in Excel
  • Categorize text with keywords in Excel
  • Calculate conditional mode with criteria in Excel
  • Group numbers with VLOOKUP in Excel
  • Group times into unequal buckets in Excel

General

  • Count cells that do not contain errors in Excel
  • How to get original number from percent change in Excel
  • How to calculate percentage discount in Excel
  • Basic text sort formula in Excel
  • Currency vs Accounting Format in Excel
© 2025 xlsoffice . All Right Reserved. | Teal Smiles | Abbreviations And Their Meaning