Macros cannot be run because the VBA support library is not installed
I've been there… I found a new macro that promised to automate a particularly annoying task, save me a ton of time and make me significantly more efficient in Excel. I tried to run the macro. And then… Something like this happened: Sigh… The first time I saw such a message in Excel, several questions popped immediately in my head:
However, since I know that I'm not the first (or last) one to raise those questions, I decided to write this post. My purpose with this tutorial is to answer the questions above and explain to you the most important things you need to know regarding how (and when) to enable macros in Excel. This way, when Excel displays a dialog saying that macros have been disabled and you need to enable macros, you'll know exactly what to do. More precisely, in this Excel tutorial we'll cover the following topics:
I assume that, if you're reading this Excel tutorial, the version of Excel you're working on still has its default settings. Therefore, let's start by understanding… Excel's Default Macro Security Setting: Disable Macros With NotificationExcel's default setting is to disable all macros with a notification. This is the reason why, if you open an Excel workbook that contains macros, you may see a message warning you that “macros have been disabled”. You can generally modify the macro security settings of Excel to determine what happens when you open an Excel workbook by determining:
In any case, please note the following:
The first question you may have is… Why Are Excel Macros Not Enabled By Default?This may sound like ancient history to most of you, but: Once upon a time, Excel (along with the other Microsoft Office applications) enabled macros by default. But then: Kwyjibo came. In case you're a Simpsons fan and are wondering whether I'm referring to Homer Simpson…
The answer is no. Sorry 😳 . I'm also a little bit disappointed. I also like the Simpsons and would've enjoyed writing about them. I'm referring to the Melissa virus, also known by other names such as Kwyjibo. This was a macro virus that propagated via a Word document sent as an email attachment. The virus became famous back in 1999. Certain large corporations (including Microsoft itself) were affected. What do you think was the consequence of this? That's right. As explained in Excel 2013 VBA and Macros by Excel experts Bill Jelen and Tracy Syrstad, Microsoft changed the default security settings of the Microsoft Office applications. Under the current setting macros are, by default, not enabled. Nowadays, macro security is very important. The reason for this, as explained by Excel authority John Walkenbach in Excel VBA Programming for Dummies is that VBA is a very powerful language. Walkenbach goes on to explain that:
Therefore, you want to understand what you're doing when enabling macros. This way you'll be able to enjoy the benefits of macros while minimizing the risk of having your computer infected with dangerous VBA code. Let's assume, that you want to enable macros in Excel because you want to start creating macros now. The following sections explain the different ways in which you can enable macros in Excel and the most important aspects of macro security settings you'll need to understand in order to be reasonably protected from macro viruses. How To Change Your Global Macro Security Settings In Order To, Among Others, Enable Macros In Excel By DefaultExcel allows you to determine whether macros are enabled or disabled automatically. You determine these default settings through the Trust Center, which is where you can see and set all the security and privacy settings for Excel. If you enable macros in Excel through the Trust Center, those settings become the new default and apply globally. If you want to enable macros for only certain Excel workbooks, you can do so by saving them in a trusted location, as I explain in the next section of this Excel tutorial. Let's see how to change your global macro security settings in 2 easy steps. This allows you to, for example, enable macros in Excel by default. Step #1: Access Excel's Trust CenterThe easiest way to access Excel's Trust Center is by simply clicking on “Macro Security” in the Developer tab of the Ribbon. Alternatively, you can get to the Trust Center through the Excel Options dialog. Do this in the following 4 simple steps. Step #1: Access the Excel Options dialog. You can get Excel to display the Excel Options dialog by:
You can also access the Excel Options dialog using keyboard shortcuts such as:
Step #2: Go to the Trust Center tab. When Excel displays the Excel Options dialog, click on “Trust Center” on the left bar of the Options Dialog. Step #3: Click on “Trust Center Settings…”. Once you're in the Trust Center tab, simply click on the “Trust Center Settings…” button on the right side of the Excel Options dialog. This takes you to the Trust Center. Step #4: Go to the Macro Settings tab. Once you're inside the Trust Center, make sure you're on the Macro Settings tab. This tab appears on the left side. If you're not already there, click on “Macro Settings”. Step #2: Select The Macro Setting You Want To EnableAt the top of the Macro Settings tab in the Trust Center, you'll find the “Macro Settings”. Excel allows you to choose 1 out of 4 separate settings to set whether Excel enables or disables macros. To choose the macro setting you want to enable, simply click on the circle on the left side of it and, then, click on the OK button on the lower right corner of the Trust Center. Let's take a look at what each of these options means and does. Option #1: Disable All Macros Without NotificationThis option is self-explanatory. It:
As you may've guessed, this is not the option you want to choose. As explained by Mr. Excel (Bill Jelen) and Tracy Syrstad in Excel 2013 VBA and Macros:
Note that this macro doesn't prevent absolutely all macros from running. As I mention above, macros in trusted locations can still run without going through the checks of the Trust Center system. Option #2: Disable All Macros With NotificationAs you've probably noticed the difference between this option and option #1 is that, now, Excel notifies you that a macro has been disabled. This is the default option in Excel and, as explained in Excel 2013 VBA and Macros, it's also the recommended setting. Excel's notification that macros are not enabled allows you to determine, on a case-by-case basis, whether you want to enable macros for a particular Excel workbook. More precisely, if you open a file that has macros (and the Visual Basic Editor isn't open), you'll see the following message below the Ribbon. If at the time of opening the workbook with macros the Visual Basic Editor is also open, Excel displays a security notice: Regardless of which of the 2 messages you see, you have 2 options. Option #1: Enable Macros. You have 2 possible ways to enable macros. Possibility #1: Simply click on “Enable Content” or “Enable Macros”. Which of the 2 options above applies depends on whether the Visual Basic Editor is open or not. If the VBE is open, you'll see the Microsoft Excel Security Notice that appears in the second screenshot above. Otherwise, you'll see the security warning that appears in the first image. Possibility #2: Enable the macros using the Backstage View by following the 3-step process below.
Option #2: Keep Macros Disabled. If the VBE is not open, ignore the message or close it by clicking on the cross at the right side of the security warning (as shown in the image below). If the VBE is open, click on “Disable Macros” or close the security notice. In all of these cases, the macros are not enabled. What Happens If You Ignore Or Dismiss The Security Warning Without Enabling Macros And, Later, Try To Run A Macro? If you try to run a macro even though you've not enable them, Excel displays the following dialog box to inform you about this: In order to solve this issue, follow the indications that appear in the dialog. Namely:
What Happens The Next Time You Open An Excel Workbook In Which You Have Enabled Macros. Excel remembers when you enable macros in an Excel workbook. Therefore, if you enable the content of such workbook following the process described in this section, the next time you open it all the macros are automatically enabled. In other words, that particular Excel file becomes a trusted document. You can enable the macros in a particular Excel file for a single time, without turning that Excel workbook into a trusted document, by following the process I explain below. As explained by Microsoft here, there are some situations in which you can't make a particular Excel workbook a trusted document. In those cases, macros are not automatically enabled the next time you open the relevant Excel file. Some of the reasons why a file can't be made a trusted document include:
When a file can't be made a trusted document, the macros that you enable by following the steps described above are only enabled for a single time. When you open the file again, Excel shows the security warning or security notice again and ask if you want to enable the content (as explained above). Option #3: Disable All Macros Except Digitally Signed MacrosThis option, just as the previous 2, generally disables macros automatically. However, in this case, the process is slightly more complicated due to the existence of an exception for digitally signed macros. If you choose this setting, Excel proceeds as follows when you open an Excel workbook with macros:
The question is, then, when should you choose this option? In Excel 2013 VBA and Macros, Excel authorities Mr. Excel (Bill Jelen) and Tracy Syrstad provide a good general rule to determine whether you should choose or not to disable all macros except those that are digitally signed:
Option #4: Enable All MacrosThis setting enables all macros automatically. However, notice the clear warning that Microsoft includes within the parenthesis: If you remember the explanation I provide above as to why Excel macros are not enabled by default, you'll see the problem with enabling absolutely all macros automatically. This macro setting leaves your computer vulnerable to macro viruses. In other words, unless you have a very compelling reason to do otherwise, its best to avoid option #4. How to Enable Macros For Certain Excel FilesIn addition to setting global settings to determine whether macros are enabled or not, you can determine the individual macro settings for particular Excel workbooks. You do this through creating and managing trusted locations, which are particular folders in your hard disk or network. As explained by Microsoft here, Microsoft Office creates several trusted locations during the installation process. Excel expert Ankit Kaul, at Excel Trick, lists the 4 locations:
Excel files that are in a trusted location are not checked according to the security settings of the Trust Center. Therefore, the macros of all the Excel workbooks that are saved in trusted locations are automatically enabled. In Excel VBA Programming for Dummies, Excel guru John Walkenbach writes that designating one or more folders as trusted locations is:
You can add a trusted location by following these 8 easy steps. Step #1: Access The Trusted Locations Tab In The Trust CenterYou can access the Trusted Locations tab in 2 simple steps. Step #1: Enter The Trust Center. The most straightforward way to get to the Trust Center is by clicking on the Macro Security button in the Developer tab of the Ribbon. You can also access the Trust Center through the Excel Options dialog, as I explain above. Step #2: Go To The Trusted Locations Tab. Once you're inside the Trust Center, make sure that you're on the Trusted Locations tab. Otherwise, you can get there by clicking on “Trusted Locations” on the left navigation pane. Step #2: Set Whether You Want To Allow Trusted Locations On NetworkTrusted locations can be both on your hard drive and on a network location. Microsoft's suggestion is that you don't have trusted locations on your network as locations outside your computer are less safe. The default setting reflects this. Additionally, according to Microsoft, you should avoid adding public folders on network shares as trusted locations. You can, however, choose to trust locations on your network by selecting “Allow Trusted Locations on my network”. Step #3: Click The Add New Location ButtonThis step is self-explanatory. Click on the Add new location… button on the lower part of the Trust Center. Step #4: Click The Browse ButtonAfter you've clicked the Add New Location button, Excel displays the Microsoft Office Trusted Location dialog. Here, you'll want to click on “Browse”. Step #5: Select The Folder You Want To Add As A Trusted LocationAfter you've clicked on the Browse button, Excel opens the Browse dialog. This probably looks familiar. This is the dialog box you'll use to select the folder you want to add to your trusted locations. You do this by following 3 steps:
The following screenshot shows how the Browse dialog looks if, for example, you wanted to add the Trusted Locations folder which is stored in the Examples folder: Step #6: Set Whether You Want To Trust Subfolders Of The Selected LocationAfter you've selected the folder to be added as a trusted location, Excel takes you back to the Microsoft Office Trusted Location dialog. Excel allows you to trust the subfolders of the location that you've selected in step #5 above by selecting “Subfolders of this location are also trusted”. If you want, you can also add a description of the trusted location, using the Description field on the lower part of the dialog. Adding a description is optional. Step #7: Click The OK ButtonOnce you've completed the 6 steps explained above, you're ready to go back to the Trust Center. To close the Microsoft Office Trusted Location dialog and go back to the Trust Center, click the OK button on the lower right corner. Step #8: Click The OK ButtonOnce you're back in the Trust Center, you'll notice that the location that you've selected by following the 7 steps above has been added to the list of trusted sources for opening files. You've pretty much completed the process to add a trusted location. Simply click the OK button on the lower right corner to finish. When To Use And When Not To Use Trusted LocationsYou're probably already aware of the following, but I'll say it anyway: You should be very careful when selecting which locations you add to the list of trusted sources for opening files in Excel. Remember that all Excel workbooks that are stored in trusted locations have their macros enabled automatically, regardless of what the global setting for macro security is. As explained at exceltrick.com, trusted locations can “act as loopholes in your security setting and any hacker can easily take advantage of those loopholes”. One example of something you don't want to do appears in Excel 2013 VBA and Macros. Here, the authors explain how Outlook stores email attachments that you double-click in a temporary folder. This temporary folder is within the local drive C:\. If you were to add C:\ and all its subfolders as trusted sources for opening files, your computer would be quite vulnerable to a macro virus. In a similar vein, Microsoft suggests that you avoid designating your entire Documents or My Documents folders as trusted locations. In this case, is better to create subfolders and add those subfolders alone to the list of trusted locations. So when does it make sense to add a trusted location? In the webpage I link to above, Microsoft provides a good rule of thumb. Basically, it may make sense to use trusted locations when you have certain Excel workbooks that you don't want the Trust Center security feature to check before opening. Doing this is safer than changing your default macro security settings in the Trust Center to something less safe. For example, let's assume that:
In this case, instead of changing your global macro security setting to Disable all macros with notification, it may make more sense for you to create a trusted location. You can then save your few Excel workbooks with macros on that trusted location and, when you open them, their macros are automatically enabled. How To Enable Macros For A Single TimeWhat can you do if you receive an Excel workbook that contains macros which you want to use but you don't want to do any of the following?
The answer is that you enable the macros for a single time in 3 easy steps, as explained below. Note that this process only works if Excel has notified you that macros have been disabled. If you have, for example, disabled all macros without notification, you'll need to change your default settings before being able to enable macros for a single time. A similar thing happens if you have disabled all macros except digitally signed ones, and open a book containing unsigned macros (in which case there is no notification). If you follow this process, Excel enables macros for as long as you keep the Excel workbook open. Since the Excel workbook doesn't become a trusted document in this scenario, if you close the file and later re-open it, the macros are not automatically enabled. Step #1: Access The Backstage ViewGo to the Backstage View by clicking on the File tab in the Ribbon. Step #2: Click On The Enable Content Button And Select Advanced OptionsOnce you're in the Backstage View, you'll notice the prominent security warning which Excel uses to inform you that macros have been disabled. Click on the Enable Content button that is to the right of the security warning. Excel displays a drop-down menu. Select “Advanced Options”. Step #3: Select “Enable content for this session” And Click The OK ButtonAfter you've clicked on “Advanced Options”, Excel displays the Microsoft Office Security Options dialog. Select “Enable content for this session” and click “OK”. That's it, macros are now enabled for that particular session. ConclusionThe quote in the image at the beginning of this Excel tutorial (from Excel authority John Walkenbach) states that Visual Basic for Applications is a powerful language. Both good and bad consequences stem from this power:
Should the potential risk of using macros stop you from using them? Generally, no. As explained by technology writer Chris Hoffman at How-To Geek:
This Excel tutorial has explained the most important things you need to know regarding how and when to enable macros. Therefore, by now, you probably have a good understanding of what activities and macro security settings are most appropriate for your particular situation. Additionally, you've also seen how you can enable macros in Excel in different situations, ranging from having them always enabled to enabling them for a single time. These different methods to enable a macro should be able to cover most of the situations that you find in your day to day work. Books Referenced In This Excel Tutorial
How install library in VBA Excel?In Microsoft Excel, you can add a library reference to the VBA project by clicking the Tools > References… manually. It will open the following dialog box which will help you to select from existing references or browse your library yourself.
Can I use VBA in WPS Office?Visual based analysis excel examples are easily available in the form of free sheet for free download from WPA office. VBA excel templates are for free download on WPS office.
Is Microsoft disabling VBA for all products?Microsoft will not block VBA macros by default in downloaded Office documents. The company has tested a default block for VBA macros since April 2022, but decided against rolling it out to general users.
|