NativeExcel for .Net Developer's Reference

IWorkbook.ProtectMethod(String)

Protects and sets the password for a workbook.

[Visual Basic]
SubProtect(_
ByValPasswordAsString_
)
[C#]
voidProtect(
stringPassword
);
[C++]
voidProtect(
String*Password
);
[JScript]
functionProtect(
StringPassword
);

Parameters

Password
A string that specifies a case-sensitive password for the workbook. If this argument is omitted, you can unprotect the workbook without using a password. Otherwise, you must specify the password to unprotect the workbook.

Example

This example sets the password for the workbook.

[C#]
book.Protect("MyPass123"); 
[VisualBasic]
book.Protect("MyPass123")
[C++]
book->Protect(S"MyPass123");

See Also

IWorkbook Interface | NativeExcel Namespace | IWorkbook.Protect Overload List | Unprotect Method