ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Protect cells (https://www.excelbanter.com/excel-programming/296387-protect-cells.html)

Fernando Duran[_2_]

Protect cells
 
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?




TroyW[_2_]

Protect cells
 
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 Duran" wrote in message
. ..
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?






Earl Kiosterud[_3_]

Protect cells
 
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.
--
Earl Kiosterud
mvpearl omitthisword at verizon period net
-------------------------------------------

"Fernando Duran" wrote in message
. ..
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 Duran[_2_]

Protect cells
 
If I protect the worksheet with a macro, do you I have to unprotect it while
writing, right?

"Earl Kiosterud" wrote in message
...
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.
--
Earl Kiosterud
mvpearl omitthisword at verizon period net
-------------------------------------------

"Fernando Duran" wrote in message
. ..
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?









All times are GMT +1. The time now is 11:51 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com