How do you edit a locked macro in Excel?

Excel for Microsoft 365 Excel 2021 Excel 2019 Excel 2016 Excel 2013 Excel 2010 Excel 2007 More...Less

To edit a macro that is attached to a Microsoft Excel workbook, you use the Visual Basic Editor.

Important: Before you can work with macros, you have to enable the Developer tab. For more information, see Show the Developer tab.

Change macro security settings

To edit and run macros, you must set the security level to temporarily enable all macros:

  1. On the Developer tab, in the Code group, click Macro Security.

    How do you edit a locked macro in Excel?

  2. Under Macro Settings, click Enable all macros (not recommended, potentially dangerous code can run), and then click OK.

    Warning: To help prevent potentially dangerous code from running, we recommend that you return to any of the settings that disable all macros after you finish working with macros.

Edit the macro

  1. On the Developer tab, in the Code group, click Macros.

  2. In the Macro name box, click the macro that you want to edit.

  3. Click Edit. The Visual Basic Editor appears.

Tip: To get help while you are working in the Visual Basic Editor, on the Help menu, click Microsoft Visual Basic Help, or press F1.

Need more help?

Z

zabiullakhan

Active Member

JoinedAug 30, 2010Messages310

  • Feb 29, 2012
  • #1

I have a excel file which is locked for editing macro.. Can you please help me unlocking this file and editing the macro.

Excel Facts

How to calculate loan payments in Excel?

Click here to reveal answer

Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.

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, Then VBAProject Properties...

How do you edit a locked macro in Excel?

Click Tools, VBAProject Properties...

  1. On the Protection tab, check "Lock project for viewing" and enter a password twice.

How do you edit a locked macro in Excel?

Enter a Password Twice

  1. Click OK.

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

How do you edit a locked macro in Excel?

The following dialog box will appear:

Password Protected from being Viewed

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".

  1. 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:

How do you edit a locked macro in Excel?

Password Protected from being Executed

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

Why won't Excel let me edit a macro?

To edit and run macros, you must set the security level to temporarily enable all macros: On the Developer tab, in the Code group, click Macro Security. Under Macro Settings, click Enable all macros (not recommended, potentially dangerous code can run), and then click OK.

How to unprotect macro without password?

Technique to Unprotect VBA Project in Excel Without Password.
Open new Microsoft Word file..
Now, press Alt + F11 keys..
Click on Insert and select a Module..
Then, Enter the following code in the General Window > > Press F5..
Now, select the Word file to unlock >> click Open..

Why are macros blocked in Excel?

VBA macros are a common way for malicious actors to gain access to deploy malware and ransomware. Therefore, to help improve security in Office, we're changing the default behavior of Office applications to block macros in files from the internet.