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.
Written by Allen Wyatt (last updated November 24, 2020)
This tip applies to Excel 97, 2000, 2002, and 2003
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:
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.
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!
You can manually copy macros from one workbook to another, but what if you want to automate the copying process? Here's ...
Discover MoreIf 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 MoreNeed to hide some macros in your workbook? There are three ways you can do it, as covered in this discussion.
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
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
@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.
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.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments