+ Reply to Thread
Results 1 to 4 of 4

Allow filtering to a protected workbook

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-22-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    329

    Allow filtering to a protected workbook

    Hi all,

    I have a code that allows access to nominated staff only, as a "Guest" only you have no access to changing any cell content, however I want to allow the "Guest" the ability to filter...don't understand why my code still won't allow filtering? See below, as always thanks for any assistance, cheers guys - Marco

    Case Else
    strFullName = "Guest " & (Environ("username"))
    For Each xlsWorksheet In ThisWorkbook.Worksheets
    xlsWorksheet.Protect Password:=PW, DrawingObjects:=True, Contents:=True, Scenarios:=True, AllowFiltering:=True, _
    userinterfaceonly:=True
    Next xlsWorksheet
    With ThisWorkbook
    .Worksheets("Jan-Jun_18").Visible = xlSheetVisible
    .Worksheets("Jan-Jun_18").Protect Password:=PW
    .Worksheets("Jul-Dec_18").Visible = xlSheetVisible
    .Worksheets("Jul-Dec_18").Protect Password:=PW
    .Worksheets("Users").Visible = xlSheetVeryHidden
    .Worksheets("Users").Protect Password:=PW
    End With
    Application.ScreenUpdating = True
    End Select
    MsgBox "Welcome " & strFullName & " you have " & strAccessLevel & vbCrLf & " " & vbCrLf & "", Title:="Welcome"
    End Sub

  2. #2
    Forum Expert
    Join Date
    10-06-2017
    Location
    drevni ruchadlo
    MS-Off Ver
    old
    Posts
    2,158

    Re: Allow filtering to a protected workbook

    You should set the code so that "UserInterfaceOnly:=True" is in the "Workbook_Open" procedure of the "ThisWorkbook" module

  3. #3
    Forum Contributor
    Join Date
    04-22-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    329

    Re: Allow filtering to a protected workbook

    Hi porucha vevrkuy,

    This code is in the "Workbook_Open", full code below. This should allow a non user, "Guest" to use filtering on the protected pages, but sadly this doesn't work? See below, thanks again for any advise - Marco

    Private Sub Workbook_Open()
    On Error Resume Next
    Dim xlsUsers As Excel.Worksheet
    Dim xlsWorksheet As Excel.Worksheet
    Dim strAccessLevel As String
    Dim strFullName As String
    Dim x As Integer
    Dim ws As Worksheet
    Dim varUserFound As Variant
    Const PW = "000"
    strAccessLevel = "Read only Access"
    Set xlsUsers = ThisWorkbook.Worksheets("Users")
    Application.StatusBar = "Copyright MadCat Productions"
    Application.ScreenUpdating = False
    varUserFound = Application.Match(Environ("username"), xlsUsers.Columns("A"), 0)
    If IsNumeric(varUserFound) Then
    strFullName = xlsUsers.Cells(varUserFound, "B").Value
    strAccessLevel = xlsUsers.Cells(varUserFound, "C").Value
    End If
    Select Case strAccessLevel
    Case "Full Administrator Access"
    For Each xlsWorksheet In ThisWorkbook.Worksheets
    xlsWorksheet.Unprotect Password:=PW
    Next xlsWorksheet
    With ThisWorkbook
    .Worksheets("Jan-Jun_18").Visible = xlSheetVisible
    .Worksheets("Jan-Jun_18").Unprotect Password:=PW
    .Worksheets("Jul-Dec_18").Visible = xlSheetVisible
    .Worksheets("Jul-Dec_18").Unprotect Password:=PW
    .Worksheets("Users").Visible = xlSheetVeryHidden
    .Worksheets("Users").Protect Password:=PW
    
    End With
    
    Case Else
    strFullName = "Guest " & (Environ("username"))
    For Each xlsWorksheet In ThisWorkbook.Worksheets
    
    xlsWorksheet.Protect Password:=PW, DrawingObjects:=True, Contents:=True, Scenarios:=True _
            , AllowFiltering:=True
    
    Next xlsWorksheet
    With ThisWorkbook
    .Worksheets("Jan-Jun_18").Visible = xlSheetVisible
    .Worksheets("Jan-Jun_18").Protect Password:=PW
    .Worksheets("Jul-Dec_18").Visible = xlSheetVisible
    .Worksheets("Jul-Dec_18").Protect Password:=PW
    .Worksheets("Users").Visible = xlSheetVeryHidden
    .Worksheets("Users").Protect Password:=PW
    End With
    Application.ScreenUpdating = True
    End Select
    MsgBox "Welcome " & strFullName & " you have " & strAccessLevel & vbCrLf & " " & vbCrLf & "", Title:="Welcome"
    End Sub

  4. #4
    Forum Contributor
    Join Date
    04-22-2012
    Location
    Australia
    MS-Off Ver
    Excel 2016
    Posts
    329

    Re: Allow filtering to a protected workbook

    Update:

    I ended up just adding a cmdbutton with:

    Sub Macro1()
    Application.DisplayAlerts = False
    ActiveSheet.Unprotect Password:="000"
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
    , AllowSorting:=True, AllowFiltering:=True
    Application.DisplayAlerts = True
    End Sub
    Does the job nicely, thanks anyway guys - Marco

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Filtering and sorting on protected sheet
    By ImranBhatti in forum Excel General
    Replies: 2
    Last Post: 09-27-2018, 10:59 AM
  2. [SOLVED] allow filtering in a protected sheet
    By sandordan_01 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-20-2018, 03:40 PM
  3. Filtering Protected Workbooks
    By vonrotz0 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 06-30-2013, 11:00 PM
  4. filtering a protected sheet
    By deth in forum Excel General
    Replies: 1
    Last Post: 06-01-2012, 06:18 PM
  5. filtering in protected sheet
    By Yaheem in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-25-2006, 06:17 AM
  6. Group, Outline, Protected Worksheets and Protected Workbook
    By BEEJAY in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-13-2006, 04:45 PM
  7. [SOLVED] Filtering a protected WS in a shared workbook - Excel 2000
    By Phuong Nguyen in forum Excel General
    Replies: 3
    Last Post: 02-18-2005, 07:06 PM

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