When I run an excel macro module in VBA, it shows the error dialog with the error message The macros in this project are disabled. This is because excel disables the macros from executing by default for security reasons. This article will tell you how to enable macros in excel and how to disable macros in excel VBA source code as well.
1. How To Enable Macros In Excel.
- Sometimes when you open an excel file, you can see a yellow SECURITY WARNING message on the top area, and there is a button with the text Enable Content.
- After you click the Enable Content button, you can find that you can run the macro in the VBA window.
- The above action will make excel trust the excel workbook file so that it enables macros in excel files also.
- If you do not see the above message, you can follow the below steps to enable macros in excel.
- Open the excel workbook, then click the File tab on the excel workbook top area.
- Then click the Options item on the bottom left corner of the excel window.
- In the popup Excel Options dialog window, click the Trust Center item on the bottom left of the dialog.
- Then click the Trust Center Settings… button on the dialog right side bottom right corner.
- It will open the Trust Center dialog window.
- Click the Macro Settings item on the left side.
- Then you can see a list of the Macro Settings radio button on the right side.
- By default, the radio button Disable all macros with notification is selected.
- If you want to run the macros in your VBA window, you should select the Enable all macros radio button.
- But this action is not recommended, so before you select it, you had better backup your excel file.
- You can also check the checkbox Trust access to the VBA project object model in the Developer Macro Settings area.
- This will enable the macros when you develop it in VBA source code also.
2. How To Enable Macros In Excel For Specified Excel Files ( Recommended ).
- The above settings will enable macros in excel globally, which means it will enable macros for all the excel files.
- If you only want to enable macros in excel for specified excel files, you can follow the below steps.
- Open the Trust Center dialog window as in section 1.
- Click the Trusted Locations item on the left side.
- Click the Add new location… button on the dialog right side.
- It will open the Microsoft Office Trusted Location dialog.
- Click the Browse… button to select the location folder path.
- If you also trust the subfolders of the selected location then check the checkbox Subfolders of this location are also trusted.
- You can also add some description in the Description text area.
- Click the OK button to save the changes.
- Then only the excel files that are saved in the trusted location folder and it’s subfolder can run the macros.
- When you run the macros in the excel file that is saved in the above folder, the warning message will disappear.
3. How To Disable Macros In Excel.
- If you enable macros in excel by the methods in section 1, then you can select the radio button Disable all macros with notification in the Trust Center dialog Macro Settings area.
- If you enable macros in excel by the methods in section 2, then you can move the excel file out of the trusted location folder to disable the macro to run.
- Or you can remove the location folder from the Trust Center —> Trusted Locations path list, then the macros will be disabled to run.