none
Hiding Content Control RRS feed

  • Question

  • Is it possible to hide a Content Control in Word 2010?

    I have a template with a company logo embedded in a Content Control in the Header section.

    During printing if the letterhead has a logo already printed, I want to hide the content control while printing.

    I check if the document has a logo based on the following code

            private bool DocumentHasLOGO()
            {
                Word.Document activeDoc = Globals.ThisAddIn.Application.ActiveDocument;

                foreach (Word.Range myStoryRange in activeDoc.StoryRanges)
                {
                    if (myStoryRange.StoryType == Word.WdStoryType.wdEvenPagesHeaderStory ||
                        myStoryRange.StoryType == Word.WdStoryType.wdPrimaryHeaderStory ||
                        myStoryRange.StoryType == Word.WdStoryType.wdFirstPageHeaderStory)

                    foreach (var cc in myStoryRange.ContentControls)
                    {
                        Word.ContentControl cCtrl = (Word.ContentControl)cc;

                        string tag = (cCtrl.Tag == null) ? String.Empty : cCtrl.Tag;
                        if (tag.Contains("Logo"))
                        {
                            return true;
                        }
                    }
                }

                return false;
            }

    Wednesday, October 17, 2012 1:20 PM

Answers

  • You can format the content control as hidden text. Roughly:

      cc.Range.Font.Hidden = true; //possibly -1 instead of true

    Then all you need to do is make sure that hidden font is not being printed (that would be the default setting):

      wdApp.Options.PrintHiddenText = false;


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Odsouza Wednesday, October 17, 2012 2:59 PM
    Wednesday, October 17, 2012 2:12 PM
    Moderator

All replies

  • You can format the content control as hidden text. Roughly:

      cc.Range.Font.Hidden = true; //possibly -1 instead of true

    Then all you need to do is make sure that hidden font is not being printed (that would be the default setting):

      wdApp.Options.PrintHiddenText = false;


    Cindy Meister, VSTO/Word MVP, my blog

    • Marked as answer by Odsouza Wednesday, October 17, 2012 2:59 PM
    Wednesday, October 17, 2012 2:12 PM
    Moderator
  • Thanks Cindy, Works for me
    Wednesday, October 17, 2012 3:01 PM