2

The line Set irm = ThisWorkbook.Permission doesn't work. It keeps giving the error

Method 'Permission' of object '_Workbook' failed.

Why is that?

Sub AddUser()
    Dim irm As Office.Permission, usr As Office.UserPermission
    Set irm = ThisWorkbook.Permission
    irm.Add "someone@hotmail.com", MsoPermission.msoPermissionView
    Set usr = irm("someone@hotmail.com")
    usr.ExpirationDate = Date + 1
End Sub
mustaccio
  • 18,234
  • 16
  • 48
  • 57
  • Is this of any help: http://stackoverflow.com/questions/1928866/who-am-i-how-to-use-microsoft-office-permission-userpermission ? – Ralph Feb 22 '16 at 10:42
  • @Ralph, It always gets stuck at the same line, it doesn't matter whether I use ThisWorkbook, ActiveWorkbook or anything else. Thanks for the link though. – monikr_on_east Feb 22 '16 at 11:06
  • Do you have any kind of restrictions imposed on the Excel file you are trying to read the permissions from? Do you have the Windows Rights Management client up and running on your computer? Maybe this is of help: https://msdn.microsoft.com/en-us/library/office/ff861518%28v=office.15%29.aspx – Ralph Feb 22 '16 at 11:18
  • @Ralph, I had an Excel file with no restrictions on it. Just in case even if it had, I had run the code with irm.RemoveAll and then adding the permissions one by one for users. And yes, I have Windows Rights Management client running on the computer. Still, no matter what basic permission related code I try to run, it always returns the same error at the same line. – monikr_on_east Feb 22 '16 at 17:13
  • Sorry, I am out of ideas (unless you have a corporate computer with domain restrictions). – Ralph Feb 22 '16 at 17:16
  • @Ralph, yeah, it happens to be a corporate computer. So, I will have to try out my personal computer. For that I will have to download Windows Rights Management services client on the computer right from the internet? RMS Client 2.1 should work with Windows 8 if all goes well, right? Then I suppose even a basic permisson VBA macro should run well. – monikr_on_east Feb 23 '16 at 04:26

1 Answers1

1

Seems like your workbook doesn't have any Permissions set. Simplest way to test that is goto File-->Protect Workbook --> Mark as Final (Office 2010) and then run your Macro and see if you still get same error.

Try setting some permissions using Windows Right Management and then try again.

Abhijeet Shukla
  • 143
  • 3
  • 9
  • I tried what you suggested but the error persists. And I have Office 2016 on computer. – monikr_on_east Feb 22 '16 at 17:15
  • @user3324369 just protect any worksheet and then try same thing again. You can use `set wb=Thisworkbook` and then use Locals window to see the different parameters of variable wb which will have Permissions – Abhijeet Shukla Feb 22 '16 at 17:37
  • @AbhijeetShukla As per MSDN [The Permission object model is available whether permissions are restricted on the active document or not .](https://msdn.microsoft.com/en-us/library/office/ff861518%28v=office.15%29.aspx) – Ralph Feb 22 '16 at 18:09