Program with Permissions
Microsoft provides the permissions objects through the Office object library since permissions can be applied to Excel, Word, and PowerPoint documents. Figure 26-18 illustrates the hierarchy of the permission objects.

Figure 26-18. Office permission object model
You must have Rights Management credentials installed before you can set permissions on a document. Otherwise, most permission methods will cause runtime errors. See the preceding section for instructions on how to install credentials.
Once credentials are installed, you can restrict access to workbooks by setting the Permission collection’s Enabled property to True, as shown here:
Dim irm As Office.Permission
Set irm = ThisWorkbook.Permission
irm.Enabled = TrueThe preceding code sets the workbook as Do Not Distribute. You are given full control, but no other users have permissions. Use the Add method to add permissions for other users. You must add each user individually, even if all have the same permissions, as shown here:
Set irm = ThisWorkbook.Permission
irm.Add "ExcelDemo@hotmail.com", MsoPermission.msoPermissionView
irm.Add "someone@microsoft.com", MsoPermission.msoPermissionViewUse Or to combine permissions for a user. For example, the following code allows ExcelDemo@hotmail.com to read, print, and copy a workbook:
irm.Add "someone@microsoft.com", MsoPermission.msoPermissionView Or & _ MsoPermission.msoPermissionPrint ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access