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

Data Analysis

  • How to conditionally sum numeric data in an Excel table using SUMIFS
  • Everything about Charts in Excel
  • How to Create Area Chart in Excel
  • Remove Duplicates Example in Excel
  • Create Scatter Chart in Excel

References

  • How to use Excel INDIRECT Function
  • Complete List of Excel Lookup and Reference Functions, References and Examples
  • INDEX function: Description, Usage, Syntax, Examples and Explanation
  • Find closest match in Excel
  • Get nth match with INDEX / MATCH in Excel

Data Validations

  • Excel Data validation unique values only
  • Excel Data validation specific characters only
  • Excel Data validation only dates between
  • Excel Data validation must contain specific text
  • Excel Data validation no punctuation

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

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

  • NOT function: Description, Usage, Syntax, Examples and Explanation
  • XOR function: Description, Usage, Syntax, Examples and Explanation
  • How to use Excel NOT Function
  • How to use Excel AND Function
  • Extract multiple matches into separate rows in Excel

Date Time

  • DAYS360 function: Description, Usage, Syntax, Examples and Explanation
  • Assign points based on late time in Excel
  • Convert Excel time to decimal seconds
  • NOW function: Description, Usage, Syntax, Examples and Explanation
  • How to calculate Next working/business day in Excel

Grouping

  • Map inputs to arbitrary values in Excel
  • Calculate conditional mode with criteria in Excel
  • Running count group by n size in Excel
  • If cell contains one of many things in Excel
  • Group numbers at uneven intervals in Excel

General

  • How to calculate decrease by percentage in Excel
  • Hide and Unhide Columns or Rows in Excel
  • Excel Default Templates
  • Convert column number to letter in Excel
  • Share Excel data with Word documents
© 2023 xlsoffice . All Right Reserved. | Teal Smiles | Abbreviations And Their Meaning