none
WORD 2010: HOW TO avoid displaying the error message "Word was unable to read the document..." when setting Cancel to true in ProtectedViewWindowBeforeEdit event? RRS feed

  • Question

  • Dear all,

    I am currently developping an Office 2010 plug-in.

    I need to use the ProtectedViewWindowBeforeEdit event and, in some occasions, set its cancel parameter to "true".

    Unfortunately, this automatically raises a message box saying that "Word was unable to read this document. It may be corrupted [...]" (I translated the message from French, so it may actually be slightly different).

    Is there a way to avoid this message or to customize its content?

    Any idea welcomed. Thanks in advance.

    - NR

    Sunday, May 20, 2012 6:30 PM

All replies

  • Hi NR

    I've tested your scenario and I don't see this message when I use the UI or code to exit protected mode. The document just stays protected. But my test is very simple. Perhaps you're doing something else or more in yours that's causing the message to appear? Does the message go away if you simply put Cancel = true; in the event and nothing else?


    Cindy Meister, VSTO/Word MVP

    Monday, May 21, 2012 8:59 AM
    Moderator
  • Hi Cindy,

    Thank you for your answer.

    I have tested this in 2 different environments (VBA + VSTO) and I get this message in both.

    Did you open your document by code?

    Here is my VBA testing, very simple:

    1) I create a Class module called CTest, with the following code:

    Option Explicit

    Private WithEvents myApp As Application

    Public Sub OpenFile(fileName As String)
        myApp.ProtectedViewWindows.Open fileName
    End Sub

    Private Sub Class_Initialize()
        Set myApp = Application
    End Sub

    Private Sub myApp_ProtectedViewWindowBeforeEdit(ByVal PvWindow As ProtectedViewWindow, Cancel As Boolean)
        Cancel = True
    End Sub

    Then in a code module, I have:

    Option Explicit

    Private ct As CTest

    Sub test()
        If ct Is Nothing Then Set ct = New CTest
        
        ct.OpenFile "<path-to-test-file>\Test.docx"
    End Sub

    Repro:

    1) Run test --> Test.docx is opened in protected mode

    2) Click on "Activate modifications" (or whatever its name is in English) --> the unwanted message appears.

    I have the same behavior with VSTO, although the scenario is a bit more complex.

    Thanks,

    - NR

    Monday, May 21, 2012 10:42 AM
  • Hi NR,

    Welcome to the MSDN forum!

    Based on my understanding, the situation occurs by design. According to the document, if the ProtectedViewWindowBeforeEdit event procedure set the Cancel parameter as True, editing is not enabled on the document. Thus, when click on the "Enable Editing", the warning message box displays.

    You need to set Cancel to False if you don't want to see the warning message box.

    Thanks.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, May 23, 2012 8:10 AM
    Moderator
  • Hi Yoyo,

    I am sorry but I don't read that this message is by design in the link you sent.

    - NR

    Wednesday, May 23, 2012 8:44 AM
  • Hi NR,

    According to the following table (Copied from the link:http://msdn.microsoft.com/en-us/library/ff192123.aspx), editing is not enabled on the document when Cancel is set to True.

    Name

    Required/Optional

    Data Type

    Description

    PvWindow

    Required

    ProtectedViewWindow

    The protected view window that contains the document that is enabled for editing.

    Cancel

    Required

    Boolean

    False when the event occurs. If the event procedure sets this argument to True, editing is not enabled on the document.

    Thus means you can not "Enable Editing" on that document. However, based on my knowledge, I partly think that the message can be misleading, cause I don't think that "Word was unable to read this document".

    I will report the situation internally later.  

    Thanks.


    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us

    Wednesday, May 23, 2012 9:09 AM
    Moderator
  • Hi Yoyo,

    I agree that setting Cancel to true disable editing, and this is my intent (I simplified the scenario for the repro, my actual scenario has a bit of logic to decides whether or not editing should be disabled for a specific document, and it also needs to display a message to inform the user why editing was disabled)

    So you've got the point: this message is misleading. Thanks for reporting it and please keep me informed on the forum.

    Thanks in advance,

    - NR

    Wednesday, May 23, 2012 9:43 AM
  • Are there any news, or progress about this topic? It is annoying to see this message. It is very missleading to clients of my addin...

    Cile

    Tuesday, March 11, 2014 1:50 PM
  • Are there any news, or progress about this topic?
    Tuesday, January 19, 2016 9:39 AM