Storing Macros in Templates

Written by Allen Wyatt (last updated December 14, 2019)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365


1

Tony has a question about the differences between macro storage in Word and Excel. In Word, macros can be stored in a document's template and you can attach a template to a particular document. Thus, Tony is able to maintain just one template and edit it to add new automation features to documents he may have created years ago. Tony wonders if there is a way to do the same in Excel so that all of his co-workers can utilize the macros stored in an Excel template on a network drive.

The short answer is that there is no way to do what you are describing. The reason is that there is an intrinsic difference between how templates are used in the two programs. In Word, a template is actively attached to a document and whenever a document is opened, the template attached to that document is also opened. If the template has changed since the last time the document was opened (for instance, if the template was updated to contain new macros), then those changes are immediately available within that document.

In Excel, templates aren't like that. True, you can create macro-enabled templates (XLTM files), and then create workbooks based on those templates. The macros in the template should end up as part of the workbook you create based on that template. But that is as far as it goes; there is no "active link" between a document and a template. If you later update the template with new macros, any workbooks previously created based on that template are not affected.

If you want to make constantly updated macros available to co-workers, there are three ways to go about doing so in the Excel environment. First, you can rely on the Personal.xlsb file. Any macros in this special workbook are available to the user because it opens whenever Excel is being used. You could set up a system to constantly update the Personal.xlsb workbook on every co-worker's system. The downside to this is that it is a pain to constantly update.

The second approach is to create a special macro-enabled workbook on a network drive that is accessible to all your co-workers. You might give it a special name, such as OurCompanyMacros.xlsm, and use it to do nothing except store your company macros. Teach all your co-workers to open this workbook whenever they use Excel, and then they will have access to any macros in the workbook. This is more manageable than the approach that relies on Personal.xlsb because you only need to update the macros in the one workbook and then all users can access them.

The third approach is to create a company add-in that contains your macros. How you create an add-in is too detailed for this tip, but you can find additional information in these ExcelTips:

https://excelribbon.tips.net/T008528
https://excelribbon.tips.net/T008529

The add-in could be stored on a network drive, and then users could install that add-in on their system and use all the macros it contains. When installing a network add-in, users are automatically given the option to copy the add-in to their local drive. If a user chooses to copy the add-in, that will defeat the ability to update the add-in and have the co-workers have access to the updated macros. The way around that is to develop some "check" in your macros to always make sure the current local add-in is the latest version. If it is not, your macro could prompt the user to perform whatever update process you might develop to make sure the add-in is up to date.

You can get just about as fancy as you want in developing and deploying add-ins. If you want more information about add-ins than you probably wanted, you might refer to this Microsoft website:

https://docs.microsoft.com/en-us/office/dev/add-ins/excel/

The bottom line is that because of the differences in how templates are conceived and implemented in Excel when compared to Word, it can be quite a bit harder to make sure that users of specific workbooks have access to updated macros for those workbooks.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (13712) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, and Excel in Microsoft 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Adjusting Comment Printouts

Need to print out comments, but in a way that you control what is included in the printout? Here's a way you can extract ...

Discover More

Generating Unique Numbers for Worksheets

You may need to automatically generate unique numbers when you create new worksheets in a workbook. Here's a couple of ...

Discover More

Centering Information in Table Cells

One of the most common ways to format information in a table is to apply some sort of alignment to the contents of table ...

Discover More

Save Time and Supercharge Excel! Automate virtually any routine task and save yourself hours, days, maybe even weeks. Then, learn how to make Excel do things you thought were simply impossible! Mastering advanced Excel macros has never been easier. Check out Excel 2010 VBA and Macros today!

More ExcelTips (ribbon)

Positioning a Column on the Screen

If you have static columns and dynamic columns on the screen, you may want the dynamic columns to always show a ...

Discover More

Deriving an Absolute Value in a Macro

Need to figure out an absolute value within your macro code? It's easy to do using the Abs function, described in this tip.

Discover More

Counting the Times a Worksheet is Used

Do you need to know how many times a worksheet has been used? Excel doesn't track that information, but you can develop ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] (all 7 characters, in the sequence shown) in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is two more than 9?

2019-12-17 11:49:35

Christian SOMMERHUBER

Hi, I'm no longer working in an environment with a network server, but I could imagine that following options may work as well:
- in the Personal.xlsb you can in Visual basic tell to link under "Tools -References..." the file stored on the server.
- I think the even better approach would be to store an AddIn on the server and to load the AddIn directly from there. I don't think that all used AddIns have to be in the default folder for AddIns.


This Site

Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.