Controlling worksheet protection via VBA

Jun 1, 2010
Reaction score
I have created a user form with VBA for data entry in an Excel worksheet. I would like to control what the user can modify and so have protected the cells.

After filling out the form I would like my VBA code to return the worksheet to its previously protected state.

I have tried to control the password protection on my worksheet via VBA using the following code:

Public Sub Protect()
Worksheets("myWorksheet").Protect Password:="password", _
End Sub

Public Sub UnProtect()
Worksheets("myWorksheet").UnProtect Password:="password"
End Sub

This works okay in that it reprotects the sheet, the only problem is that the level of protection is too high. I had previously allowed formatting of columns, rows and cells but now the sheet is completely locked.

Is there any way to pass an argument into this protect subroutine so that I can control the level of protection?



Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question