Protect cells

  • Thread starter Thread starter Fernando Duran
  • Start date Start date
F

Fernando Duran

I'm trying to write in a worksheet using a macro, I have no problem, as long
the worksheet isn't protect. But I want to protect the file, so, the user
wont be able to change anything.. can I get some help in this problem?
 
Fernando,

Below is some simple code that will work in any version. This is one
approach to take.
1) Unprotect the sheet; 2) make your changes; 3) Protect the sheet.

You don't say which version of Excel you will be using. The newer versions
have additional features for the Protection command. Search the Excel Visual
Basic Help for "Protect Method" for more details (UserInterfaceOnly may be
of interest to you also).

Troy


Sub Test1()
'''Unprotect the sheet.
ActiveSheet.Unprotect

'''Your code to make changes.
ActiveSheet.Range("A1").Value = "Hello"
'''...

'''Protect the sheet.
ActiveSheet.Protect
End Sub
 
Fernando,

Protect the workbook in a macro, like this:

Sheets(MySheet).Protect UserInterfaceOnly:=True ' Password:="MyPass" '
Password optional.

Or your macro can unprotect the sheet, make its changes, then protect it.
 
If I protect the worksheet with a macro, do you I have to unprotect it while
writing, right?
 

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

Back
Top