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

后端 未结 8 1535
我寻月下人不归
我寻月下人不归 2021-02-19 20:07

We\'ve had these few lines of code running happily in our applications for several years (and in several versions of Office, 2003, 2007, 2010 etc). Purpose is to perform a kind

相关标签:
8条回答
  • 2021-02-19 20: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.

    0 讨论(0)
  • 2021-02-19 20:29

    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.

    0 讨论(0)
  • 2021-02-19 20:33

    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.
    0 讨论(0)
  • 2021-02-19 20:37

    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, ...);
    
    0 讨论(0)
  • 2021-02-19 20:39

    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!

    0 讨论(0)
  • 2021-02-19 20:42

    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.

    0 讨论(0)
提交回复
热议问题