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 Moving Between Worksheets.

Disabling Moving Between Worksheets

Written by Allen Wyatt (last updated December 22, 2018)
This tip applies to Excel 97, 2000, 2002, and 2003


Excel provides a variety of ways that you can move from one worksheet to another in a workbook. If you want to disable moving between worksheets, you've got a difficult task in front of you because of the variety of methods you need to do something about.

For instance, one way to move between worksheets is to press Ctrl+Page Up or Ctrl+Page Down. To disable these keys for a particular workbook, you need to use the OnKey method, in the following manner:

Private Sub Workbook_Activate()
    Application.OnKey "^{PgDn}", ""
    Application.OnKey "^{PgUp}", ""
End Sub
Private Sub Workbook_Deactivate()
    Application.OnKey "^{PgDn}"
    Application.OnKey "^{PgUp}"
End Sub

These two macros should be placed in the ThisWorkbook object. The first is run whenever the workbook is activated and it disables Ctrl+Page Up and Ctrl+Page Down by having nothing run when they are pressed. The second macro is run when the workbook is deactivated, and re-enables the keys.

There are still a number of other ways to switch between worksheets, such as manually selecting the sheet, using Go To, using hyperlinks, etc. The easiest way to prevent moving between worksheets is to hide the worksheets you don't want accessed. Protecting the workbook and protecting the VB project will also aid in "thwarting" the user from moving between sheets.

If the sheets are hidden, they cannot be selected and thus you cannot move to them. Go To will not go to them, hyperlinks will not go to them. If you want users to be able to view the hidden worksheets later, you must create a macro routine with your own controls/buttons to go to those sheets. This routine would "unhide" the sheet you are going to, and hide the one you just left.

Depending on your needs, there is one other approach you can try. You could add the following macro to the ThisWorkbook object:

Private Sub Workbook_SheetDeactivate(ByVal mySheet As Object)
    Application.EnableEvents = False
    mySheet.Activate
    Application.EnableEvents = True
End Sub

This macro is executed every time the current worksheet is deactivated. It essentially "reactivates" the worksheet that is being left, which means that no other worksheet can ever be selected.

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 (3333) 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 Moving Between Worksheets.

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

Adding Lines in an Equation Editor Matrix

If you are using matrices in your equations, you can add lines to a matrix by applying this tip.

Discover More

Limiting Entries to Numeric Values

When creating a worksheet, you may need to limit what can be entered into a particular cell. Using data validation you ...

Discover More

Setting Data Validation Input Messages

When using data validation, you might want to have Excel display a message when someone starts to enter information into ...

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 (menu)

Freezing Top Rows and Bottom Rows

Freezing the top rows in a worksheet so that they are always visible is easy to do. Freezing the bottom rows is not so ...

Discover More

Returning a Worksheet Name

Need to know the name of the current worksheet? You can use the CELL function as the basis for finding this information ...

Discover More

Viewing Same Cells on Different Worksheets

When switching from one worksheet to another, you might want to view the same portion of the new worksheet that you were ...

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 1 + 1?

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