none
How to know a content control is grouped or not? RRS feed

  • Question

  • Hello All,

    I call Word.ContentControl.UnGroup method, but this method will throw exception "This command is only valid for group content controls." if the control is not grouped already. How can I know a content control is grouped or not? By this, I will check before calling UnGroup method.

    I appreciate all your helps.

    Thanks,

    Vu


    Wednesday, April 20, 2011 8:33 AM

Answers

  • Hi Vu

    While Ungroup is a method in the Word interop, there is no equivalent method for grouping. Instead, you have to create a new content control of the type wdContentControlGroup. If, for example, I want to group the first two content controls in a document:

      Dim rngGroup As word.Range
      
      rngGroup = doc.Range(doc.Contentcontrols(1).Range.Start - 1, doc.Contentcontrols(2).Range.End + 1)
      rngGroup.Select
      doc.Contentcontrols.Add wdContentControlGroup, rngGroup
    
    
    

    Cindy Meister, VSTO/Word MVP
    Thursday, April 28, 2011 6:47 AM
    Moderator

All replies

  • Hello All,

    I call ContentControl.UnGroup method, process something and want to regroup. How can I do this?

    Thanks for your helps in advance.

    Regards,

    Vu

    Wednesday, April 20, 2011 8:35 AM
  • Hi Vu

    Is this using VSTO content controls, or Microsoft.Office.Interop.Word content controls? Which version of Word?


    Cindy Meister, VSTO/Word MVP
    Thursday, April 21, 2011 5:26 AM
    Moderator
  • Hi Cindy,

    I'm sorry to reply you late. I'm using Microsoft.Office.Interop.Word content controls. My Word version is 2007.

    Thanks in advance for your helps.

    Regards,

    Vu

    Sunday, April 24, 2011 2:39 PM
  • Hi Vu

    While Ungroup is a method in the Word interop, there is no equivalent method for grouping. Instead, you have to create a new content control of the type wdContentControlGroup. If, for example, I want to group the first two content controls in a document:

      Dim rngGroup As word.Range
      
      rngGroup = doc.Range(doc.Contentcontrols(1).Range.Start - 1, doc.Contentcontrols(2).Range.End + 1)
      rngGroup.Select
      doc.Contentcontrols.Add wdContentControlGroup, rngGroup
    
    
    

    Cindy Meister, VSTO/Word MVP
    Thursday, April 28, 2011 6:47 AM
    Moderator