Share via


Error message when you try to unprotect an IRM-protected workbook programmatically in Excel 2013: "Run-time error: 1004"

 

This post is an extension to a KB article mentioned below that was written for Excel 2003.

https://support.microsoft.com/en-us/kb/914199 

But I encountered few issues where the requirement was to have the same behaviour confirmed for Excel 2013.

Hence created a scenario for the same using Unprotect and Protect Method.

image

 

Hello Command Button

Would just pop a message saying Hello.

I placed it to show that a function like MsgBox has no issues executing with IRM protection applied to the workbook.

Unprotect Command Button

It calls the Unprotect Method to remove protection from the current sheet.

Protect Method

I am calling the Protect Method here the moment I click on any cell.

Code :

Private Sub CommandButton1_Click()
MsgBox "Hello"
End Sub

Private Sub CommandButton2_Click()
ActiveSheet.Unprotect Password:="hello"
End Sub

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
ActiveSheet.Protect Password:="hello"

End Sub

Scenario 1 :

Workbook that I have not protected using Protect Method and applied IRM protection to it.

Saved it and then opened it with another user , who has almost all permissions just not full control that the owner of the document will have.

Permissions the user holds.

image

Now when I select on any cell the Protect Method gets called and we receive the following error.

image

 

Scenario 2 :

Workbook that I have protected using Protect Method and applied IRM protection to it.

Saved it and then opened it with another user , who has almost all permissions just not full control that the owner of the document will have.

Now when I click Unprotect Command Button , got the following error.

image

 

As already mentioned this is by design and mentioned in the following KB Article.

https://support.microsoft.com/en-us/kb/914199 

But if the user has full control over the document , we will not encounter such a situation.

Kaustubh Dwivedi

Microsoft Security Support Escalation Engineer