Saving an Unsavable Workbook

Written by Allen Wyatt (last updated June 29, 2024)
This tip applies to Excel 2007, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


Bill has a "before save" macro that tests three cells. If the cells are empty, then the macro stops the user from saving. In other words, they are required to fill in the cells before they can save the workbook. Bill would like to save this workbook as a template, but when he clears the three cells, the macro also stops him from saving as a template. He would like the template to be "clean," with a default of the three cells being empty. Users would create a new workbook based on the template and then (correctly) not be able to save unless the cells are filled in. Bill wonders how he can save the workbook as a template, with the three cells empty.

There are several approaches you could take to save your template. The first is to change the name of your workbook to something rather esoteric, such as X27TT3W.xlsm. Then, add some logic to your "before save" macro that checks to see if the name of the base workbook is X27TT3W. If it is, then allow the workbook (or template) to be saved regardless of the condition of the three cells. Once the template is saved, you can then rename it in Windows to your desired name, and it can be shared with your users. Unless they guess the esoteric name you chose, they won't be able to save the workbook without making sure the three cells are filled in.

Another approach is to simply add another event handler to your workbook—this one that executes when you first open the workbook—to clear the contents of the three cells. This could be something simple, like this:

Private Sub Workbook_Open()
    Sheet1.Cells(1,1).Clear
    Sheet1.Cells(2,1).Clear
    Sheet1.Cells(3,1).Clear
End Sub

This macro clears the cells at A1:A3. If you want to have it clear a different range, just change the three lines to reflect which cells you want to clear. Then, put something in the three cells (so that it passes your testing in the "before save" macro), and save it as a template.

Another approach that is very easy to implement is to simply disable events before you save the template. This is not done within a macro, but within the Immediate window in the Visual Basic Editor. All you need to do is enter this single line:

Application.EnableEvents = False

Immediately save your workbook as a template, and then enter the following line in the Immediate window of the Visual Basic Editor:

Application.EnableEvents = True

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

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

Including a Printer's Name in a Footer

If you can produce output on a number of different printers, you may want Word to indicate on your printouts which ...

Discover More

Getting Rid of Empty Rows after Importing

Import data into a worksheet (or paste it there) and you may find that you end up with a group of blank cells you need to ...

Discover More

Finding Long Sentences

For certain types of writing, you may want to make sure that the sentences in your document do not exceed a certain ...

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)

Getting a File Name

Does your macro need to allow the user to specify a particular file name that should be used by the macro? Here's a quick ...

Discover More

Macros in Two Workbooks Interfere with Each Other

Having macros in multiple open workbooks can sometimes produce unexpected or undesired results. If your macros are ...

Discover More

Counting Empty Colored Cells

There are a variety of ways that you might want to count the cells in your worksheet. One way is to figure out how many ...

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 7?

There are currently no comments for this tip. (Be the first to leave your comment—just use the simple form above!)


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.