none
Tracking events to check whether a section break is inserted RRS feed

  • Question

  • I am working with Word 2007, C# and VSTO with 2010. My question is if there is a way to know programmatically when a section break is inserted. Is there any event to track this? I am facing an issue where I need to check the range that has just been inserted for a section break, if one is found then compare it to the previous or next section break and do some other work. Thanks in advance.
    Thursday, December 9, 2010 12:39 PM

Answers

  • Hi Sayan

    <<then how to find the previous or next section break? I want to compare them for some properties. >>

    There are various ways to "address" a section; which to use depends a lot on what you want to do, exactly.

    Taking your question literally, you can use Range.Find.Text = "^b" to find a section break character. But you don't need the section break character, itself, to compare properties - at least, not as far as I know.

    If all you want is the Section object, then

    1. You can get the current section index using: wdApp.Selection.Sections.Item(1).Index
    (This would probably be get_item in C#)

    2. From that, you can determine the index value for the next or previous section

    3. Then to get that Section object: wdDoc.Sections[sectionIndex]


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Sayan.Chaudhuri Wednesday, December 15, 2010 10:37 AM
    Monday, December 13, 2010 8:29 AM
    Moderator

All replies

  • Hello Sayan,

    Thanks for posting. We’re doing research on this issue. It might take some time before we get back to you. Have a nice day.

    Best regards,
    Bessie Zhao - MSFT
    MSDN Subscriber Support in Forum
    If you have any feedback of our support, please contact msdnmg@microsoft.com.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, December 10, 2010 2:24 AM
  • Hi Sayan

    There's no event that's triggered when inserting a section break.

    But what you could do is include a Ribbon XML in your VSTO project. Put a <commands> section in it. with a <command> element for each built-in command you want to "track". Assign a callback to the onAction property of these commands. When the macro runs, that can be your "event trigger". The callback can execute the actual command the user wants to use, and perform any custom actions.


    Cindy Meister, VSTO/Word MVP
    Friday, December 10, 2010 10:14 AM
    Moderator
  • Hi Cindy,

    Thanks for your reply. However that's how we are handling events and custom actions in our VSTO application. So the only option for me is to use Application_WindowSelectionChange(Selection) event to track whenever something is inserted/changed. If I am in middle of a document and inserting a new section break there, then how to find the previous or next section break? I want to compare them for some properties. Appreciate your help.


    Sayan Chaudhuri
    Friday, December 10, 2010 10:46 AM
  • Hi Sayan

    <<then how to find the previous or next section break? I want to compare them for some properties. >>

    There are various ways to "address" a section; which to use depends a lot on what you want to do, exactly.

    Taking your question literally, you can use Range.Find.Text = "^b" to find a section break character. But you don't need the section break character, itself, to compare properties - at least, not as far as I know.

    If all you want is the Section object, then

    1. You can get the current section index using: wdApp.Selection.Sections.Item(1).Index
    (This would probably be get_item in C#)

    2. From that, you can determine the index value for the next or previous section

    3. Then to get that Section object: wdDoc.Sections[sectionIndex]


    Cindy Meister, VSTO/Word MVP
    • Marked as answer by Sayan.Chaudhuri Wednesday, December 15, 2010 10:37 AM
    Monday, December 13, 2010 8:29 AM
    Moderator
  • Thanks Cindy. I appreciate your help.
    Sayan Chaudhuri
    Wednesday, December 15, 2010 10:38 AM