VBA Automation for Excel 2019 Cookbook
上QQ阅读APP看书,第一时间看更新

Using the Trust Center for macro security

This recipe is all about security, at least as far as macros are concerned. We will show you where to find the Trust Center in Excel, and after that, how to choose between four levels of macro security.

Getting ready

We've successfully created and tested our macro. We've even made some changes to the code by editing it in the VBA Editor. The final step is to have 02_RecordMacro.xlsm open in order to set the macro security.

How to do it…

Proceed with the following steps for this recipe:

  1. Activate the backstage view by clicking on File:

    Figure 1.23 – The backstage view

  2. From the category list on the left, select the last one, Options. The Excel Options dialog box appears:

    Figure 1.24 – The Excel Options dialog box

  3. Select the last category on the left, Trust Center, and then click on the Trust Center Settings button on the right:

    Figure 1.25 – Macro Settings in the Trust Center dialog box

  4. Select the Macro Settings category on the left. The details will be displayed on the right.
  5. Click the second radio button from the top, Disable all macros with notification.
  6. Click on OK to close the Trust Center dialog box.
  7. In the Excel Options dialog box, click on OK.

How it works…

Macro Settings has four levels of security in order to prevent viruses from entering your system. These options are as follows:

  • Disable all macros without notification: Choosing this option will enable all macros. It is safe but defeats the purpose of creating macros.
  • Disable all macros with notification: This is the standard setting, selected by most users. A yellow message bar will appear when you open a file with an embedded macro. If you know and trust the person that sent the file, go ahead and disable the macros. If not, do not enable the macros.
  • Disable all macros except digitally signed macros: Only macros that have a digital signature are allowed to run. However, you will still receive a security warning for signatures that haven't been marked as trusted.
  • Enable all macros: This setting is not recommended because potentially dangerous code can run. Unless you are not connected to the internet, or any other computers in a LAN, never choose this option.

There's more…

The keyword here is vigilance. In this day and age, computer security is vital. A good starting point would be to always have an anti-virus application running on your PC. It is better to be safe than sorry.