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.
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
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 (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.
Program Successfully in Excel! John Walkenbach's name is synonymous with excellence in deciphering complex technical topics. With this comprehensive guide, "Mr. Spreadsheet" shows how to maximize your Excel experience using professional spreadsheet application development tips from his own personal bookshelf. Check out Excel 2013 Power Programming with VBA today!
When processing information using a macro, you may need to know if there are any other instances of Excel running on a ...
Discover MoreWhen reading information from a text file, your macro may need to start reading at a place other than the beginning of ...
Discover MoreIf you have a macro that takes a long time to process a workbook, you might want to continue working in Excel while the ...
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: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
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.
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