none
Word 2010 header edition RRS feed

  • Question

  • Hi,

    I am sorry, I am posting a question about DSOFramer control in VSTO forums.

    I am using word 2010 and DSOFramer control to embedded word document in winforms application and I have to enter the header edit mode I am using the code below :

    if (wordDocument.ActiveWindow.View.SplitSpecial != WdSpecialPane.wdPaneNone)
            wordDocument.ActiveWindow.Panes[2].Close();
          if (wordDocument.ActiveWindow.ActivePane.View.Type == WdViewType.wdNormalView ||
            wordDocument.ActiveWindow.ActivePane.View.Type == WdViewType.wdOutlineView)
            wordDocument.ActiveWindow.ActivePane.View.Type = WdViewType.wdPrintView;
          wordDocument.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekCurrentPageHeader;
    

    but the application become unresponsive when executing this line : 

          wordDocument.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekCurrentPageHeader;
    
    

     Best regards.

     

    • Moved by Cindy Meister MVPModerator Wednesday, July 13, 2011 3:03 PM not using VSTO technology (From:Visual Studio Tools for Office)
    Wednesday, July 13, 2011 2:48 PM

Answers

  • I found a solution to the problem : the content control selection must be done before changing the SeekView property

    First :

    contentControlInHeader.range.Select();

    then : 

     

    if (wordDocument.ActiveWindow.View.SplitSpecial != WdSpecialPane.wdPaneNone)
                                wordDocument.ActiveWindow.Panes[2].Close();
                            if (wordDocument.ActiveWindow.ActivePane.View.Type == WdViewType.wdNormalView ||
                                wordDocument.ActiveWindow.ActivePane.View.Type == WdViewType.wdOutlineView)
                                wordDocument.ActiveWindow.ActivePane.View.Type = WdViewType.wdPrintView;
    wordDocument.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekCurrentPageHeader;
    

     

    This will select the content control in the header then activate the header edition.

    • Marked as answer by Tunisian_BB Friday, July 15, 2011 8:55 AM
    Friday, July 15, 2011 8:54 AM

All replies

  • It's a very, very, very bad idea to work with selections in Word unless there's absolutely no other way to accomplish something. When you use SeekView, you're working with the current selection - you're emulating the user.

    If you want to manipulate the content of the header/footer, work with the corresponding Range. Just as an example:

      Word.Range rng = oDoc.Sections[1].Headers[Word.WdHeaderFooter.wdHeaderFooterPrimary].Range;
      rng.Text = "Text left\tText Center\tText right";


    Cindy Meister, VSTO/Word MVP
    Wednesday, July 13, 2011 3:08 PM
    Moderator
  • Thank you Cindy for your response and your advice, but my goal is to emulate the "Modify header" action to enable header content controls selection. In my case when the user select a node in a tree I want to select the corresponding content control located in the header (header can contain many content controls). using contentControl.Range.Select() open new panel "First page header", see the image below :

     

    Regards



    • Edited by Tunisian_BB Friday, July 15, 2011 9:10 AM image link
    Wednesday, July 13, 2011 5:04 PM
  • I found a solution to the problem : the content control selection must be done before changing the SeekView property

    First :

    contentControlInHeader.range.Select();

    then : 

     

    if (wordDocument.ActiveWindow.View.SplitSpecial != WdSpecialPane.wdPaneNone)
                                wordDocument.ActiveWindow.Panes[2].Close();
                            if (wordDocument.ActiveWindow.ActivePane.View.Type == WdViewType.wdNormalView ||
                                wordDocument.ActiveWindow.ActivePane.View.Type == WdViewType.wdOutlineView)
                                wordDocument.ActiveWindow.ActivePane.View.Type = WdViewType.wdPrintView;
    wordDocument.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekCurrentPageHeader;
    

     

    This will select the content control in the header then activate the header edition.

    • Marked as answer by Tunisian_BB Friday, July 15, 2011 8:55 AM
    Friday, July 15, 2011 8:54 AM