Forum Discussion
Ghalder
Feb 05, 2024Copper Contributor
Assigning sheets to user in online document
Hello. i am in desperate need of a Vba code to limit ussers Access to an online sheet. I have a worksheet With 24 sheets. the stores are putting in somme info for ther own store. and ther have bee...
JKPieterse
Feb 05, 2024Silver Contributor
Ghalder You have probably found out by now that you cannot hide all sheets. So the trick is to first show the sheet that you want shown and then hide all others:
Private Sub Workbook_Open()
Dim currentUserName As String
' Hent e-postadressen fra Microsoft-kontoen
currentUserName = Application.Session.CurrentUser.Address
' Vis kun det spesifikke arket for hver bruker
Select Case UCase(currentUserName)
Case "email address removed for privacy reasons"
HideAllSheetsExcept "NyttArk101"
Case "email address removed for privacy reasons"
HideAllSheetsExcept "NyttArk102"
Case "email address removed for privacy reasons"
HideAllSheetsExcept "NyttArk103"
' Legg til saker for andre brukernavn og ark
End Select
End Sub
Sub HideAllSheetsExcept(sheetName As String)
Dim sht As Worksheet
' Vis kun det spesifikke arket
Worksheets(sheetName).Visible = xlSheetVisible
For Each sht In Worksheets
If sht.Name <> sheetName Then
sht.Visible = xlSheetHidden
End If
Next
End SubGhalder
Feb 05, 2024Copper Contributor
thanks for the help.
I havent had the time to future look into it afther i posted, but removng hide all sheets make senes .
I havent had the time to future look into it afther i posted, but removng hide all sheets make senes .