Microsoft Office documents, in my case: PowerPoint presentations, may have limited permissions. How can I find out, programmatically, what permissions of my code are in this document?
All I can find on MSDN on this topic is: http://msdn.microsoft.com/en-us/library/aa432118.aspx
If I run the following code, I get a list of users who have permissions for this document:
Sub test() Dim perm As Office.Permission Set perm = ActivePresentation.Permission Debug.Print "Enabled=" & perm.Enabled If perm.Enabled Then Debug.Print "PermissionFromPolicy=" & perm.PermissionFromPolicy Debug.Print "PolicyName='" & perm.PolicyName & "'" Debug.Print "PolicyDescription='" & perm.PolicyDescription & "'" Dim uperm As Office.UserPermission For Each uperm In perm Debug.Print uperm.UserId & ", " & uperm.Permission Next uperm End If End Sub
Output Example:
Enabled=True PermissionFromPolicy=False PolicyName='Do Not Distribute' PolicyDescription='Permission is currently restricted. Only specified users can access this content.' john@doe.com, 64 user@system.de, 33 myname@example.com, 33
"Resolution" is a bitmap whose definition I found in Microsoft's public header files:
enum MsoPermission { msoPermissionView = 1, msoPermissionRead = 1, msoPermissionEdit = 2, msoPermissionSave = 4, msoPermissionExtract = 8, msoPermissionChange = 15, msoPermissionPrint = 16, msoPermissionObjModel = 32, msoPermissionFullControl = 64, msoPermissionAllCommon = 127 };
However, this does not tell me what specific permissions my code has. If I only knew who I was (in terms of UserPermission.UserId), I could find my rights in the Permission object. But I can not find this information. What am I missing?
Known methods for obtaining a Windows username (username for the current user on this Windows machine). Unfortunately, this is not the user ID that is checked when PowerPoint decides what permissions I have in the document. To emphasize: PowerPoint provides a user interface that allows me to change who I am at runtime. Obviously, this does not change the login username (that is, the name returned by ADVAPI). PowerPoint usernames refer to them, are identified / authorized through Microsoft Passport.
Thanks in advance! Volker