Word Interop Error - "This method or property is not available because the current selection is in a limited editing zone"

Ken Blaker 1 Reputation point
2023-01-06T18:37:21.14+00:00

I have an application manages some documents using MS Word interop, and works perfectly on one computer, but fails on another.

Here's what the code does, and what happens:

         Microsoft.Office.Interop.Word.Document templateDoc = winWord.Documents.Open(ref templateFileName, ReadOnly: true, Visible: true);  
        //activate the template doc  
        templateDoc.Activate();  
        winWord.ActiveDocument.Content.NoProofing = 1;   
        templateDoc.Words.Last.InsertBreak(Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak);  

When I get to the last line - the insert page break - I get an error one one of the machines, that states:
"This method or property is not available because the current selection is in a limited editing zone."

One other machine the insert is fine. I am using the same template file in both cases.

Since this varies between the 2 computers I also checked to see which version of MS Word is installed.
The machine that does not get the error is running Word version 15726.20262
The machine that gets the error is running Word version 15928.20198

I also checked the versions of the Microsoft.Office.Interop.Word nuget package. Both machines are using 15.0.4797.1004 - the latest stable version.

Both were set up using our company MS365 subscription, and I've checked for latest updates on both - they update to these different versions.

Can this be fixed? Is this an MS bug, or is there something I need to check on my side?

Developer technologies | C#
{count} votes

1 answer

Sort by: Most helpful
  1. Ken Blaker 1 Reputation point
    2023-01-09T18:08:58.227+00:00

    Hi JackJJun-MSFT,

    I actually fixed my problem already. Here's an update:

    1 - the software had run well on my main computer for years, and until a few days ago. That machine is running Windows 10 Pro, build 19045.2364. It is running Word version 15928.20198.

    2 - the other computer is a Microsoft Cloud Computer, running Windows 10 Enterprise, build 19045.2364, with Windows Feature Experience Pack 120.2212.4190.0.

    3 - the file shown in the code as a "template" is not a word template file - it is a .docx file that i use as a prototype. (I don't think it matters for this thread, but what the application does is to take the prototype and then append another file to it - and then I loop through the whole document to clean up formatting, styles, replacing certain characters or strings, etc.)

    The issue turns out to be that I open the prototype file with the ReadOnly property set to true - see above.

    The fix was to copy the prototype (so that the original does not get altered), open it as ReadOnly: false, and then go through my process.

    My guess is that the latest update of the Word kernel is more "strict" about the ReadOnly property and does not allow editing at all. The old version allowed editing but required that the resulting file get saved to a new name (which is what I used to do).

    I ended up solving this through guesswork - so what i find frustrating is that I'd have been in a better position to understand what changed if I had been able to look up the exception message and get a clear understanding of what it meant ("This method or property is not available because the current selection is in a limited editing zone."), and I sure wish there had been documentation of this being a change from the earlier version of Word that had worked up until a few days earlier - and continues to work on the un-upgraded machine.

    I hope this helps. Like every other MSFT developer, my days always ping pong between admiration and frustration with MSFT.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.