gruhnelliot
New Member
- Joined
- Jun 4, 2013
- Messages
- 14
I have a workbook that has 6 different worksheets that you log into with a password specific for each sheet. 5 of the worksheets are for user interface and the 6th worksheet is for admin. I would like to protect the workbook so the users have rights to enter data, but not add or delete worksheets. Is this possible? Every VBA code I have tried doesn't work.
This is the code I have for the workbook:
rivate Sub Workbook_Open()
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",false)"
Application.DisplayFormulaBar = False
Dim wksuserlog As Worksheet
Dim lngnextrow As Long
On Error Resume Next
Set wksuserlog = ThisWorkbook.Worksheets("User Log")
On Error GoTo ExitProc
If wksuserlog Is Nothing Then
Set wksuserlog = ThisWorkbook.Worksheets.Add
wksuserlog.Name = "User Log"
wksuserlog.Range("a1:b1").Value = Array("Username", "Date_time")
End If
With wksuserlog
lngnextrow = .cells(.Rows.Count, "a").End(xlUp).Row + 1
.cells(lngnextrow, "a").Value = Environ("Username")
.cells(lngnextrow, "b").Value = Now()
.Columns("a:b").AutoFit
End With
ExitProc:
Dim Ws As Worksheet
Application.DisplayAlerts = False
Application.ScreenUpdating = False
For Each Ws In ActiveWorkbook.Worksheets
If Ws.Name <> "Login" Then
Ws.Visible = xlSheetVeryHidden
End If
Next Ws
LoginUF.Show
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",True)"
End Sub
This is the code I have for the workbook:
rivate Sub Workbook_Open()
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",false)"
Application.DisplayFormulaBar = False
Dim wksuserlog As Worksheet
Dim lngnextrow As Long
On Error Resume Next
Set wksuserlog = ThisWorkbook.Worksheets("User Log")
On Error GoTo ExitProc
If wksuserlog Is Nothing Then
Set wksuserlog = ThisWorkbook.Worksheets.Add
wksuserlog.Name = "User Log"
wksuserlog.Range("a1:b1").Value = Array("Username", "Date_time")
End If
With wksuserlog
lngnextrow = .cells(.Rows.Count, "a").End(xlUp).Row + 1
.cells(lngnextrow, "a").Value = Environ("Username")
.cells(lngnextrow, "b").Value = Now()
.Columns("a:b").AutoFit
End With
ExitProc:
Dim Ws As Worksheet
Application.DisplayAlerts = False
Application.ScreenUpdating = False
For Each Ws In ActiveWorkbook.Worksheets
If Ws.Name <> "Login" Then
Ws.Visible = xlSheetVeryHidden
End If
Next Ws
LoginUF.Show
End Sub
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.ExecuteExcel4Macro "SHOW.TOOLBAR(""Ribbon"",True)"
End Sub