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

Selecting a Paper Source

When you print a worksheet, you may want to specify that the printout be done on a particular paper tray in a particular ...

Discover More

Using Object Anchors

An object anchor is used to signify the point at which an object is inserted into a document. If you want to see these ...

Discover More

Finding Other Instances of Excel in a Macro

When processing information using a macro, you may need to know if there are any other instances of Excel running on a ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More ExcelTips (menu)

Detecting Types of Sheets in VBA

When processing workbook information in a macro, you may need to step through each worksheet to make some sort of ...

Discover More

Combining Worksheets from Many Workbooks

Do you need to pull a particular worksheet out of a group of workbooks and combine those worksheets into a different ...

Discover More

Shortcut to Move between Two Worksheets

Moving between to adjacent worksheets is easy; Excel provides a shortcut key to do the trick. If you want to move between ...

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?

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.