“You are not allowed to edit this selection because it is protected.” but only since Office 2013?

£可爱£侵袭症+ 提交于 2019-12-04 02:57:29

In desperation, trawling for answers even in blog posts and discussions far removed from this particular error it seems there's been a change in Office 2013 to the default treatment of the ReadingLayout.

Introducing the line w.ActiveWindow.View.ReadingLayout = False seems to have solved our problem.

We had some C# automation that worked fine with Word 2007/2010, but stopped with Word 2013 with the same "You are not allowed ..." warning.

Following steps on this site solved the issue.

Basically there are two settings to check:

  • File – Options – General. Uncheck “Open E-Mail attachments and other uneditable files in reading view”
  • File – Options – Trust Center – Trust Center Settings. Select Protected View, then clear all the checkboxes.
CrazyIvan1974

You don't specify how the document is opened, but a problem I had was resolved by following the answer accepted on this question.

Switching from WordApplication.Documents.Open() to WordApplication.Documents.Add() resolved the issue for my application.

Tim Dol

In my case, this error was caused by the presence of content controls with .LockContentControl == true.

To work around this issue, I built an IEnumerable<ContentControl> of the content controls with this property set to true, and set .LockContentControl = false. Now I can .InsertColumnsRight() without a problem. Then I restore the .LockContentControl = true for all content controls in my collection.

Tried most of the suggestions above but I found this fixed the problem. We were opening the doc as a template in read-only with a password. So couldn't use 'Add'

Documents.Open(strTemplateDoc, ReadOnly:=True, PasswordDocument:=strDocPassword, Visible:=False)

Setting the View.Type to wdNormalView stopped the error "You are not allowed to edit this selection because it is protected"

wdDocPage.ActiveWindow.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdNormalView

Thanks to all the others for their suggestions - they helped a lot.

This has been happening to me for the past two days (while creating a dotm template) and what fixed it for me was to create a new normal.dotx! Don't know if that will work for others or not, but it did for me!

When you open a document, specify that it should not be opened as read-only

object readOnly = false; 
doc = word.Documents.Open(ref path, ref miss, ref readOnly, ...);

For me, the issue was similar to Tim Dols answer, but I needed to unlock the content of the content control., which is the LockContents property: mycontentcontrol.LockContents = False

For @CrazyIvan1974, the problem with that solution is that Add creates a new document. if you point at an existing document when using Add, it doesn't load the document, it creates a new document using the original as a template. That can disconnect templates and add-ins, really messing you up if you save over the original

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!