+ Reply to Thread
Results 1 to 2 of 2

user not allowed to change sheet

Hybrid View

  1. #1
    Registered User
    Join Date
    03-31-2009
    Location
    Portugal
    MS-Off Ver
    Excel 2007
    Posts
    59

    user not allowed to change sheet

    Hello again

    I want to make a book complety impossible to change from sheet to sheet (that can only be done by buttons that redirect the user to that specific sheet)

    Is there a way to do this?

  2. #2
    Forum Expert Paul's Avatar
    Join Date
    02-05-2007
    Location
    Wisconsin
    MS-Off Ver
    2016/365
    Posts
    6,887

    Re: user not allowed to change sheet

    Hi Sonyk,

    The following macro does what I think you're after. Start by hiding all of the worksheets in the workbook (except one, of course, since Excel requires one worksheet as visible). Add this code to your ThisWorkbook module (in the VB Editor window) and then on the Review ribbon, Protect the Workbook. The code below uses a workbook protection password of "aaa".

    The code, which could be attached to a toolbar button (rather than a button on each sheet in the workbook), simply asks the user which sheet they want to go to - and it provides a list of all of the worksheets available in the workbook. The user just needs to type the name of the worksheet in the space provided and press OK. The macro will unprotect the workbook, hide the active sheet, open the new sheet, then re-protect the workbook.

    Hope that helps!
    Option Explicit
    
    Sub listSheetsAndGo()
    Dim i As Integer, mySheets() As Variant, shCount As Integer
    Dim strSheets As String, ans As String, currSht As String
    
    Application.ScreenUpdating = False
    currSht = ActiveSheet.Name
    shCount = Sheets.Count
    ReDim mySheets(shCount - 1)
    
    For i = 1 To shCount
        mySheets(i - 1) = Sheets(i).Name
    Next i
    strSheets = Join(mySheets, ", ")
    ans = InputBox("Which sheet would you like to go to?" _
        & vbCrLf & vbCrLf & strSheets, "Sheet Navigator")
    
    If ans = currSht Then
        MsgBox "You're already on sheet: " & ans
    Else
        On Error GoTo errHandler
        ThisWorkbook.Unprotect Password:="aaa"
        Sheets(ans).Visible = True
        Sheets(currSht).Visible = False
        ThisWorkbook.Protect Password:="aaa"
        On Error GoTo 0
    End If
    
    Application.ScreenUpdating = True
    Exit Sub
    
    errHandler:
    Application.ScreenUpdating = True
    ThisWorkbook.Protect Password:="aaa"
    MsgBox "An incorrect sheet name was entered."
    End Sub
    Last edited by Paul; 04-23-2009 at 01:22 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1