Please Note: This article is written for users of the following Microsoft Excel versions: 97, 2000, 2002, and 2003. If you are using a later version (Excel 2007 or later), this tip may not work for you. For a version of this tip written specifically for later 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 November 24, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003


5

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 (3288) applies to Microsoft Excel 97, 2000, 2002, and 2003. You can find a version of this tip for the ribbon interface of Excel (Excel 2007 and later) 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

Moving Cells Using the Mouse

Want to easily move information from one cell to another? A quick way to do it is to simply drag and drop using the mouse.

Discover More

Selecting Tabs in Dialog Boxes

Dialog boxes normally present information in a series of tabs. If you want to move from tab to tab without taking your ...

Discover More

Renaming a File

Need to rename a file in a macro? It's easy to do using the Name command, as discussed in this tip.

Discover More

Professional Development Guidance! Four world-class developers offer start-to-finish guidance for building powerful, robust, and secure applications with Excel. The authors show how to consistently make the right design decisions and make the most of Excel's powerful features. Check out Professional Excel Development today!

More ExcelTips (menu)

Automating Copying Macros

You can manually copy macros from one workbook to another, but what if you want to automate the copying process? Here's ...

Discover More

Hiding Macros

Need to hide some macros in your workbook? There are three ways you can do it, as covered in this discussion.

Discover More

Aborting a Macro and Retaining Control

If you need to exit a macro before it is finished running, you can do it using a brute force method, or you can build in ...

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 nine minus 5?

2022-08-02 05:19:58

Boris

Hi Allen,
Although I have not found any way of setting it, I have workbooks that open and ignore the shift key being pressed (ie run workbook_opne code - unless application.enableevents is false - and run auto_open code etc). In the <File><Info> section, under <Protect Workbook>, they include "Shift key on Open" - which can be unprotected without a password but 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). This may be becaus I have changed the error handling behaviour (brek on all errors and back to break on unhandled errors) or something but I have not deliberately trapped teh shift key behaviour...
{[fig}]


2022-06-07 07:33:06

Andries

In office 2021 (LTSC) the shift option does not work anymore ? I have to change some VBA code but the auto_open will run although I pressed the shift while opening the file.

By default all macro's are enabled in this company as the users still rely a lot on them and I'm not permitted to temporary disable them before opening t sheet.

Is there any quick other option to temporary disable vba code being executed ?


2021-08-14 15:28:03

BARRY

@abhishek

As you cannot run any code at start-up; you have to hide all the useful worksheets just prior to closing the workbook or whenever the workbook is saved. Excel conveniently provides you with the appropriate events.

I use exactly this code in the sample workbook that you can download from : http://bit.ly/2cqcSts.
This is the subject of another tips on this site "Protecting Individual Worksheets, by User" https://excel.tips.net/T001952_Protecting_Individual_Worksheets_by_User.html


2021-08-13 04:22:26

sunny

How to Manually Turn On/Off Conditional formatting with Function Key w/o VBA ?
Worksheet.EnableFormatConditionsCalculation


2021-08-12 21:37:43

abhishek

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

Sir could you please help me with the code? As I want to hide all the worksheet if the user press the shift key while opening the file.


This Site

Got a version of Excel that uses the menu interface (Excel 97, Excel 2000, Excel 2002, or Excel 2003)? This site is for you! If you use a later version of Excel, visit our ExcelTips site focusing on the ribbon 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.