So far we developed various macros according to numerous requirements. So today I’m going to show you how to lock them with passwords. Because once you developed a macro you may want to lock it as it is your intellectual property. Also you may want to lock the project to protect it from being wrecked by other users.
So now let’s see how we can lock the project. Follow these easy steps. First open the Excel file containing the macro. Then click somewhere in the worksheet. Next press Alt + F11 on your keyboard. This will open the VBA editor.
Alternatively, you can go to the “Developer” tab and click on “Visual Basic” to open the VBA editor as well.
Note that the “Developer” tab is not displayed by default. This post explains how to add it to the ribbon.
As you can see in the first image, I have a very simple macro in the module1. To lock the project first click on the “Tools” menu.
Then select “VBAProject Properties...”
“Project Properties” dialog box will open. Go to the “Protection” tab and check the “Lock project for viewing”. Then enter the password in both textboxes and click OK.
Save the file, close it and reopen. Now when you go to the VBA editor and try to expand the project from project explorer it will ask you the password to unlock.
So if a user doesn't have a password then he/she can't view the code. But they can still run the macros from the developer tab. Thus anyone can run the macro without messing it up.
However if you want you can also protect the macro execution with a password too.
Lock Macro Execution (Using Password)