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

Easily Adding Blank Rows

Want to add a bunch of blank rows to a your data and have those rows interspersed among your existing rows? Here's a ...

Discover More

Absolutely Getting Rid of Formatting

Need to get rid of the formatting applied to a bunch of text? One of the easiest ways to do this is to use Notepad in ...

Discover More

Sorting by Headings

Headings are a great way to organize your document. If, after getting your headings in place, you want to sort by those ...

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)

Protecting a Worksheet's Format

You can protect various parts of your worksheets by using the tools built into Excel. One thing you can protect is the ...

Discover More

Ordering Worksheets Based on a Cell Value

Need to sort your worksheets so that they appear in an order determined by the value of a cell on each worksheet? Using a ...

Discover More

Jumping to Alphabetic Worksheets

Got a workbook with a lot of worksheets in it? Here's some handy ways to jump to the worksheet you want, alphabetically.

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 two more than 7?

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.