none
Adding comment generates misleading events RRS feed

  • Question

  • My Word Addin uses the OnWindowSelectionChange event to track which paragraph the user is working within. But if the user does  "New Comment" then I get the event with a selection range with very low numbers like 1, 2, 3, 4. This makes my code believe (incorrectly) that the user has moved to the first paragraph. Is there a way I can detect that the user is working within a comment, not within the document, so I can filter out these misleading events?

     

     

    Monday, June 9, 2014 5:49 PM

Answers

  • Hi Scott,

    The StoryType of the selection will determine what kind of content you have selected, please check this code example:

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                Globals.ThisAddIn.Application.WindowSelectionChange += Application_WindowSelectionChange;
            }
    
            void Application_WindowSelectionChange(Word.Selection Sel)
            {
                if (Sel.StoryType == Word.WdStoryType.wdCommentsStory)
                {
                    MessageBox.Show("Comments selected");
                }
                else if (Sel.StoryType == Word.WdStoryType.wdMainTextStory)
                {
                    int paragraphNumber = Globals.ThisAddIn.Application.ActiveDocument.Range(0, Sel.Paragraphs[1].Range.End).Paragraphs.Count;
                    MessageBox.Show(paragraphNumber.ToString());
                }
                else
                { 
                    //...
                }
            }

    Check more information here:

    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.wdstorytype(v=office.15).aspx


    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, June 10, 2014 7:45 AM
    Moderator

All replies

  • Hi Scott,

    The StoryType of the selection will determine what kind of content you have selected, please check this code example:

    private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                Globals.ThisAddIn.Application.WindowSelectionChange += Application_WindowSelectionChange;
            }
    
            void Application_WindowSelectionChange(Word.Selection Sel)
            {
                if (Sel.StoryType == Word.WdStoryType.wdCommentsStory)
                {
                    MessageBox.Show("Comments selected");
                }
                else if (Sel.StoryType == Word.WdStoryType.wdMainTextStory)
                {
                    int paragraphNumber = Globals.ThisAddIn.Application.ActiveDocument.Range(0, Sel.Paragraphs[1].Range.End).Paragraphs.Count;
                    MessageBox.Show(paragraphNumber.ToString());
                }
                else
                { 
                    //...
                }
            }

    Check more information here:

    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.wdstorytype(v=office.15).aspx


    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, June 10, 2014 7:45 AM
    Moderator
  • Excellent! Thank You.
    Tuesday, June 10, 2014 1:15 PM