none
How to figure out the region from which the content is selected in word 2007? RRS feed

  • Question

  • Hi All,

    For word 2007, we are customizing context menu by adding some buttons in it. We are doing it by adding command buttons in the context menu.

    we are doing it for the following areas/regions in the word document.

    • Footnotes
    • Endnotes
    • Table Text
    • Table Headings
    • Text
    • Lists
    • Hyperlink Context Menu
    • Headings
    • Comment

    We have a specific requirement that we need to enable some of these context menus only when the text is selected. Is there a way to figure out that the selected content is from which area/region(from the above list) in a word document?

    To know whether the selected content is from footnote/endnote/WithinTable, we use following API’s.  we are calling the below function on Application_WindowBeforeRightClick event.

    public static void EnableDisableContextMenu(Microsoft.Office.Interop.Word.Selection selection)

            {

                if (selection == null) return;

               

                bool IsFootnote = selection.get_Information(Microsoft.Office.Interop.Word.WdInformation.wdInFootnote);

                bool IsEndnote = selection.get_Information(Microsoft.Office.Interop.Word.WdInformation.wdInEndnote);

                bool IsInTable = selection.get_Information(Microsoft.Office.Interop.Word.WdInformation.wdWithInTable);

                …

    }

    Similarly, are there any API’s available to know the same thing for the remaining items in the list?

    Tuesday, June 19, 2012 3:44 PM

Answers

  • You can query the StoryType object. For example:
    Msgbox Selection.StoryType

    For Word's help file:

    WdStoryType Enumeration
    Specifies the story type of a selection or item.
    Name Value Description
    wdCommentsStory 4 Comments story.
    wdEndnoteContinuationNoticeStory 17 Endnote continuation notice story.
    wdEndnoteContinuationSeparatorStory 16 Endnote continuation separator story.
    wdEndnoteSeparatorStory 15 Endnote separator story.
    wdEndnotesStory 3 Endnotes story.
    wdEvenPagesFooterStory 8 Even pages footer story.
    wdEvenPagesHeaderStory 6 Even pages header story.
    wdFirstPageFooterStory 11 First page footer story.
    wdFirstPageHeaderStory 10 First page header story.
    wdFootnoteContinuationNoticeStory 14 Footnote continuation notice story.
    wdFootnoteContinuationSeparatorStory 13 Footnote continuation separator story.
    wdFootnoteSeparatorStory 12 Footnote separator story.
    wdFootnotesStory 2 Footnotes story.
    wdMainTextStory 1 Main text story.
    wdPrimaryFooterStory 9 Primary footer story.
    wdPrimaryHeaderStory 7 Primary header story.
    wdTextFrameStory 5 Text frame story.

    Cheers
    Paul Edstein
    [MS MVP - Word]


    Wednesday, June 20, 2012 12:47 AM