none
Word 2007 Content Control in a Text Box

    Question

  • Has anyone tried to access Word 2007 content control while it is in a text box?

    It seems that content controls aren't enumerated when they are in text boxes, but when I convert text box to frame everything works OK. I've tried plain and rich text content controls.

    Document doc = Globals.ThisAddIn.Application.ActiveDocument;
                   
    foreach (Word.ContentControl myControl in doc.ContentControls)
    {
       string myStr = myControl.Tag;
       MessageBox.Show(myStr);
    }

    Word 2007 B2TR, VSTO 2005 SE final

    Friday, November 10, 2006 10:25 AM

Answers

  • By "text box" I assume you mean a "drawing object".

    The problem with putting anything in a drawing object is that it's not really part of Word. The Drawing tools are something supplied by Office, and the internal Word processes (that date back to the late eighties) have little knowledge of them. Frames, on the otherhand, are entirely part of Word so their contents are picked up.

    If you really want to use text boxes, you can also loop through the Shapes collection, checking  TextFrame.HasText. If that's true, then you can loop through the ContentControls in the TextRange.

    Friday, November 10, 2006 10:43 AM
    Moderator

All replies

  • By "text box" I assume you mean a "drawing object".

    The problem with putting anything in a drawing object is that it's not really part of Word. The Drawing tools are something supplied by Office, and the internal Word processes (that date back to the late eighties) have little knowledge of them. Frames, on the otherhand, are entirely part of Word so their contents are picked up.

    If you really want to use text boxes, you can also loop through the Shapes collection, checking  TextFrame.HasText. If that's true, then you can loop through the ContentControls in the TextRange.

    Friday, November 10, 2006 10:43 AM
    Moderator
  • Thank you for quick reply. You've understood me correctly.

    I am already using frames so I don't need text boxes, but have run into some issues with older documents which had to be adapted to use content controls instead of bookmarks. Interestingly, bookmarks can be accessed the way I wrote in the previous message.

    Anyway, content controls can be accessed directly without Word installed and source code for Word 2007 Content Control Toolkit is of a big help here (http://www.codeplex.com/Wiki/View.aspx?ProjectName=dbe)

     

     

     

    Friday, November 10, 2006 11:34 AM
  • Hi Bojan

    Yes, I know ContentControls can be accessed directly in an Open XML file, but I hadn't seen this tool before. Thanks for the link :-)

    FWIW, once an older file has been saved in the new 2007 format, you can also get at the bookmarks through the XML file format, without needing to automate Word.

    Friday, November 10, 2006 1:03 PM
    Moderator