none
Accessing Selection.StoryType from Reviewing Pane leads to run-time error RRS feed

  • Question

  • Hi,

    I found a very weird behavior of Word 2010 and VSTO (same applies for VBA though).When selection is in the Reviewing Pane, running the line below will raise a run-time error.

    The erroneous code:

    public static void Application_WindowChangeSelection(Selection sel){ if (sel.StoryType != WdStoryType.wdMainTextStory)

    ...

    }

    The error:

    So after a quick debugging I found that if the selection is within the Reviewing Pane, then when trying to access the StoryType property, will throw exception:

    Error HRESULT E_FAIL has been returned from a call to a COM component.

    Question is why this happening and how can I detect when selection is in Reviewing Pane and eliminate this run-time error?
    I tried catching the exception and returning from the ChangeSelection event in that case, but it then leads to a strange behavior where the selection in this pane remains, even if the user is making another selection.

    Thanks,

    Etai.

    Wednesday, October 22, 2014 4:44 PM

All replies

  • Hello Etai,

    I think VSTO is not related to the code shown above. I'd suggest asking Word specific questions on the Word for Developers forum.

    Wednesday, October 22, 2014 5:10 PM
  • Hi Etai,

    Based on the description, you got the exception when the selection is in review panes.

    I could preroduce the issue however when I use the Try-Catch code to handl the execption the selection worked well for me.

    Could you provide a code sample that help us to reproduce the issue( selection remains in the reivew pane)?

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Thursday, October 23, 2014 8:37 AM
    Moderator
  • Hi Fei,

    Subscribe to the WindowChangeSelection event and use this code:

    public static void Application_WindowChangeSelection(Selection sel){

        try
        {
            if (sel.StoryType != WdStoryType.wdMainTextStory)
            {
                return;
            }
        }
        catch
        {
            return;
        }

    }

    Now try to open a document with some comments, open the review pane and try making a selection of length > 0.

    For me most of the time it doesn't work. The selection will disappear, or it will remain, and when you will make another selection in the pane, it will be added to the last one.

    Let me know if you were able to reproduce this.

    Thanks

    Etai

    Thursday, October 23, 2014 10:00 AM
  • Hi Etai,

    Thanks for the code snippet for reproducing this issue.

    I still failed to reproduce this issue, the version of Word I tested is 14.0.7015.1000. I suggest that you try to update the Office to latest version or repair the Office to see whether this issue was fixed.

    Hope it is helpful.

    Best regards

    Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, October 28, 2014 5:47 AM
    Moderator