Aetherix
Aetherix

Reputation: 2250

Protect workbook but allow changes by code

I'm looking for the equivalent of the following statement, but for workbook protection:

Worksheet.Protect "Password", UserInterfaceOnly := True

So I don't want the user to tamper with the workbook, but changes by code are fine.

Upvotes: 0

Views: 117

Answers (1)

user2204167
user2204167

Reputation:

this is not possible as Workbook.Protect() method has no such parameter. Rather you can try to unprotect the workbook... do your code... protect the workbook again.

Public Sub UserProtection()
    Const PASS As String = "666bytes" 
    ThisWorkbook.Unprotect (PASS)
    '...YOUR CODE...what you want to do...
    ThisWorkbook.Protect (PASS)
End Sub

Also, let me remind you that keeping the password in plain string format (like in this example) is not a good practice. (not that it will help very much if someone wants to crack your sheet) ... :) just FYI

Upvotes: 2

Related Questions