PDA

View Full Version : lock workbook



elmnas
10-05-2015, 02:15 AM
Hello people,

I have made a program in vba.

When a user presses on the button in the excel sheet below
it opens a form.
14505

The user puts data in the form which generates data into the sheet.
I need a code that locks the workbook and the sheets.
The user should only be able to modify data by using the form.
All other cells/worksheets should be locked (i.e. the user is not allowed to modify the workbook under any circumstance).

I am using a module to call the form module in vba.


Sub myrun()


Form.Show


End Sub


Could someone help me?

Thank you in advance

Kenneth Hobs
10-05-2015, 06:15 AM
In ThisWorkbook's object, I add this code. It lets code change protected cells. Change ken to your password and add other protect options to suit.

Private Sub Workbook_Open() Dim ws As Worksheet
For Each ws In Worksheets
ws.Protect "ken", UserInterfaceOnly:=True 'True allows code to change data.
Next ws
End Sub