Is it possible to protect a workbook that has VBA codes written in it?

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
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
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.
does it have to be a VBA code that does it - just as easy to manually do it -

To have it to where they can only change the data or enter data- u can unlock cells u want them to be able to update and lock the work page down- right clicking tab protect worksheet-
for workbook- go to file protect workbook and structure so they cant add and remove tab's (sheets)
 
Upvote 0
That doesn’t work. When I protect the workbook or worksheet, the VBA codes that create the password protected login screen generate an error. Then the workbook can be opened without the password.
 
Upvote 0

Forum statistics

Threads
1,223,909
Messages
6,175,314
Members
452,634
Latest member
cpostell

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top