本文转自:https://www.ablebits.com/office-addins-blog/2014/07/22/enable-macros-excel/#always-run-macros
This tutorial teaches how to enable macros in Excel 2010-2013. You'll also find step-by-step instructions showing how to disable macros in Excel or turn them on via Message bar and Backstage view. In addition you'll find a tip to run a macro even if all macros are disabled and get a link to a piece of code that gets users enable macros in a workbook.
First off, I'd like to share a brief intro to Excel macros and security risk linked to enabling them. A macro is a series of commands assembled together and designed to automate frequent routine tasks in Excel. You can run macros any time to perform certain actions.
Many macros are created using Visual Basic for Applications, or VBA. Lots of Excel users can record simple macros to streamline their work with spreadsheets. Developers create codes that are more complicated.
When enabling a macro in Excel that was written by someone else, you need to remember that it can carry a potential security risk. A person with malicious intent, like hacker, can make a destructive macro to spread a virus on your PC or network.
Read on to find detailed descriptions of macro settings, steps to enable Excel macros and save a macro-enabled workbook. You can also click any of the links below to get straight to the point.
How to enable macros in Excel from the Message Bar
If you open an Excel document that contains macros, you'll see the yellow Message Bar with a shield icon and the Enable Content button.
If you are sure, the macros are from a trustworthy source, just press the Enable Content button on the bar.
The file will be opened as a trusted document and the security warning will disappear.
Excel - enable macros via the Backstage view
You can also enable macros in Excel using the Microsoft Office Backstage view. You can see the yellow Message Bar if you click the File tab.
- Click on the File tab.
- You'll see the yellow Security Warning area. Click Enable Content.
- You will see 2 features: Enable All Content and Advanced Options. Select Enable All Content to always make the document's active content available.
The current Excel file will become a trusted document and all macros will be enabled.
How to always run macros for a trusted worksheet
If you create and share workbooks with macros you may want to avoid getting the security message every time. If you get all your workbooks only from reliable sources, you can choose to instantly run all macros for all publishers. Below you'll see how to enable all macros in Excel by default.
- Go to File -> Options -> Trust Center and press the Trust Center Settings ... button.
- You will see the Trust Center window. Select the Macro Settings option.
- Select the radio button Enable all macros (not recommended, potentially dangerous code can run).
From now on all macros will run without warning.
Please note that this setting makes your computer open to viruses. You should be sure you get all workbooks with macros only from the trusted publishers.
Adjust macro settings on the Trust Center window
You can find all macro settings on the Trust Center window. These settings let you adjust the way you want to work with macro-enabled workbooks.
Follow the steps from How to always run macros for a trusted worksheet to get the Trust Center window.
Please see all the macro settings explained below:
- Disable all macros without notification. Macros and security alerts regarding them get turned off.
- Disable all macros with notification. If you select this radio button, macros will be disabled, but security alerts will appear if there are macros in a file. It lets you enable macros in Excel depending on the source.
- Disable all macros except digitally signed macros. In this case, macros are turned off, security alerts appear and digitally signed by a trusted publisher macros run. If you have not trusted the publisher, you are offered to enable the signed macro and trust the publisher.
- Enable all macros (not recommended, potentially dangerous code can run). All macros run without warning. Please note that this setting makes your computer open to viruses.
- Trust access to the VBA project object model. This checkbox forbids or allows programmatic access to the Visual Basic for Applications (VBA) object model from an automation client. This security setting is for the code that computerizes an Office program and manipulates VBA environment and object model. For automation clients to access the VBA object model, the user running the code must grant access. You need to tick the check box to give access.
Run a macro even if all macros are disabled
Say the setting Disable all macros without notification is turned on your PC, but you need to run certain macro here and now. If you have Excel 2007-2013, you can enable macros even if your security settings don't allow this. The point is that Excel sees certain locations as trusted zones. This means if you store your macro-enabled files there, the security check can be omitted and the macro will run.
Please see the list of these trusted locations below:
Program Files\Microsoft Office\Templates
Program Files\Microsoft Office\Office12\Startup
Program Files\Microsoft Office\Office12\Library
Program Files\Microsoft Office\Office12\XLSTART
You can add any location on your PC to the trusted zone, by following the steps below:
- In Excel navigate to the File tab -> Options -> Trust Center -> Trust Center Settings -> Trusted Locations.
- Click on the Add new location button to see the Microsoft Office Trusted Location dialog box.
- Click Browse to search for the needed place on your PC.
How to save a macro in a workbook
Macros need you to save the files in a new macro-enabled workbook format. This type adds security warning to your file. If you don't choose the correcttype, the command will not be kept. Below you'll find how to save a macro-enabled Excel document:
- Navigate to File -> Save As and browse for the necessary location on your PC.
- Click on the Save as type: arrow and select the Excel Macro-Enabled Workbook from the list of types.
- Click Save to keep the results.
If you forget to select the type of Macro Enabled Workbook, you'll get a warning message notifying that the macro will not be saved:
Click No if you need to keep the macro.
How to disable macros in Excel 2010-2013
Suppose, you only proofread the files and don't need macros enabled on your PC. You get documents from various sources and prefer to set your security settings to the highest level. Since some macros can be potentially dangerous, you can disable them all using the Trust Center options.
- Follow the steps from How to always run macros for a trusted worksheet to get the Trust Center window.
- Select the Disable all macros without notification or Disable all macros with notification radio button. If you go for the first option, you will not know if there are any macros in the current file. The second button lets you identify Excel workbooks that contain macros.
Use special code to make users enable macros in a workbook
The code from this article forces a user to enable macros in a workbook. This code hides all sheets until the macro is enabled. It also adds a warning sheet that alerts the user to run macros. As soon as a user turns the commands on, the warning sheet is hidden and all other content is shown.
- Add the code to your workbook.
- Create a new sheet named "Warning".
- Add a message on the worksheet asking the user to re-open the workbook and enable macros.
- Finally, save your workbook.
You may also be interested in
Check out Tutorial with Excel examples about Macros for some nice and simple samples to automate your daily spreadsheet tasks.
If you are starting to learn macros, read How to insert and run VBA code in Excel - tutorial for beginners.
That's all about enabling and disabling macros in Excel. Hope you've found the information helpful. Feel free to leave your questions in the comments below. Be happy and excel in Excel!