Closing a Read-Only Workbook

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


Gary has a read-only workbook that multiple users can access. They can modify cells but not save their work. On exiting the workbook, Gary wants Excel to just close without informing the user that it is read-only and giving them the option of saving a copy.

This is best accomplished by using a macro to modify the Saved flag in the workbook, just before closing. This flag indicates, internally, whether a workbook needs saving or not. If the flag is False, then Excel knows that the workbook has not been saved (changes have been made without saving). If your macro sets the flag to True, then Excel will close directly because it thinks that all the changes have been saved.

Here's what the macro should look like, at its simplest:

Private Sub Workbook_BeforeClose(Cancel As Boolean)
  If ThisWorkbook.ReadOnly Then
    ThisWorkbook.Saved = True
  End If
End Sub

The macro should be added to the ThisWorkbook object in the VBA Editor. That way, it is automatically executed just before the workbook is closed. The flag is set to True, and when the macro ends, Excel continues with its normal closing procedures. Since Excel thinks that there are no unsaved changes, the user sees no message and the workbook is closed.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the ExcelTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

ExcelTips is your source for cost-effective Microsoft Excel training. This tip (10349) 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

Numbers in Base 12

Different professions use numbers in entirely unique ways. You may need to come up with a number that represents the ...

Discover More

Expanding a Custom Dictionary

Does Word tell you that your custom dictionary is full? It might not actually be full, but even if it is you can add ...

Discover More

Open Workbooks Don't Display

Have you ever opened a workbook, only to have it not display your worksheet data? This can be very disconcerting, but it ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (ribbon)

Stopping a Workbook from Persistently Auto-Loading

Excel has the capability to automatically open workbooks when you first start the program. You may not want to have one ...

Discover More

Seeing a Worksheet Thumbnail in Windows

When you save a workbook, you have the opportunity to save a thumbnail image that can be displayed within Windows. Here's ...

Discover More

Discovering Dependent Workbooks

When you starting linking information from one workbook to another, those workbooks become dependent on each other. ...

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 6 + 5?

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.