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

Resetting a Single Shortcut Key

Need to get rid of a keyboard shortcut key you previously defined? It's easy to do if you follow these steps.

Discover More

Printing Columns and Rows

If you want to print just the contents of a number of rows and columns, it can be challenging to get the output you want. ...

Discover More

Turning Off the Date and Time Shown in a Comment

When you add a comment to a document, Word helpfully includes the date and time that the comment was added. If you don't ...

Discover More

Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!

More ExcelTips (ribbon)

Creating Default Formatting for Workbooks and Worksheets

Not satisfied with the way that default workbooks and worksheets look in Excel? You can easily create your own defaults ...

Discover More

Viewing Workbook Statistics

Excel keeps track of a range of stats about each workbook you use. If you want to take a look at those stats, it's easy; ...

Discover More

Comparing Workbooks

Do you need to compare two workbooks to each other? While you can use specialized third-party software to do the ...

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 8 - 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.