Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Disabling Shift Key Use when Opening a Workbook.

Disabling Shift Key Use when Opening a Workbook

Written by Allen Wyatt (last updated August 2, 2022)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021


3

The VBA capabilities of Excel are quite astounding. VBA is a full-blown programming language, which means you can do most anything with it. Some folks have even written entire applications in VBA; applications that build upon the Excel environment to accomplish a specific task.

If you've written such a system, you no-doubt rely on the automatic macros that run when you first start Excel or open a workbook. It is common to use these macros to configure the Excel environment and start the application running. It is frustrating to think that someone could disable your entire system simply by holding down the Shift key when opening the workbook. (Holding the Shift key disables any of the automatic macros associated with a workbook.)

There is no way in Excel to disable the Shift-key bypass of startup macros. The reason is quite simple—security. If this feature could be blocked or disabled it would be possible for macro viruses to start running, without the user being able to do anything about it. This would be very bad.

One possible workaround is to not have the workbook do anything useful if the startup macros are not allowed to run. The default worksheet that displays when the workbook is opened should say something to the effect that the workbook must be opened with the macros enabled in order to function properly. The user could then be directed to close the workbook and try again.

In this default condition, the other worksheets in the workbook could be set to a "very hidden" state. This is done by setting the Visible property of each sheet to xlSheetVeryHidden. With this property set, the worksheets cannot be manually made visible; this can only be done via VBA.

If the user opens the workbook and the macros successfully run, they could hide the default worksheet or simply delete it. The macro could then unhide the "very hidden" worksheets, as necessary, to implement the application in the way desired.

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 (10281) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Excel here: Disabling Shift Key Use when Opening a Workbook.

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

AutoFill Won't Work as Expected

AutoFill is a great tool for filling cells with data. What do you do when it doesn't work like you expect, however? ...

Discover More

Controlling Display of Page Breaks

Do you want page breaks displayed on the screen? Excel allows you to specify whether it should show those page breaks or not.

Discover More

Printing a Number of Different Pages

If you don't need to print an entire workbook, it can be confusing to figure out how to print just certain pages. This ...

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)

Delaying in a Macro

At times, you may want your macro to pause execution. This tip presents four different ways you can add a delay into your ...

Discover More

Deleting Every X Rows

Grab some info from a source other than Excel, and you may find the need to delete a certain pattern of rows from a ...

Discover More

Selecting a Range of Cells Relative to the Current Cell

When processing information in a macro, you often need to select different cells relative to the currently selected ...

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

2022-08-02 05:35:00

Boris

Hi Allen,
I added this under the same article for earlier versions of excel but it belongs here so I am repeating it...
Although I have not found any way of setting it, I have workbooks that include "Shift key on Open" - under <File><Info> section, under <Protect Workbook>. This can be unprotected without a password but it is there ...
Indeed, in my envrionment (WIndows 11 Professional, Office 2019 Professional), the shift key seems always to be ignored and auto_open will always execute (even when there is no "Shift key on Open" under the Protect Workbook) (Workbook_open and otehr event macros will not run if Application.EnableEvents is set to false before opening the workbooks; and I am usually - though not always - presented with the enable of disable macros option message box on opening). Ignoring teh shift key on open may be because I have changed the error handling behaviour (break on all errors and back to break on unhandled errors etc) or something but I have not deliberately trapped the shift key behaviour...
{[fig}]


2016-04-24 19:47:24

Petros

"Holding the Shift key disables any of the automatic macros associated with a workbook" is not accurate.

A user just prevents Workbook events (Open, Activate etc) from firing by holding down the Shift key during startup. Macros work OK as demonstrated in the link provided by Frans

Use the onLoad event handler and protect VBA & customUI using Unviewable+. Read more:

http://www.spreadsheet1.com/unviewable-vba-project-app-for-excel.html


2013-03-13 16:11:51

Frans

Hi Allen,
Great tips, thanks.
Quote: "There is no way in Excel to disable the shift-key bypass of startup macros."
Yes there is a way. See http://pixcels.nl/disable-shift-key-on-open/
Excel!
- Frans


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.