Group shapes

2005-08-31
2013-04-17
  • Nobody/Anonymous

    I'd like to group shapes in a worksheet and i don't know what to do.
    Here is my code :

    Object[] arglist1 = new Object[1];
    String[] str_grp = new String[2];

    // idpt is a new TextBox (Shape)
    IDispatch idpt = (IDispatch)((IDispatch)sheet.get("Shapes")).method("AddTextbox",arglist);
    // idpf is a new Shape
    IDispatch idpf = (IDispatch)((IDispatch)sheet.get("Shapes")).method("AddShape",arglist);

    // argument of the propertie "Range"
    str_grp[0] = (String) idpt.get("Name");
    str_grp[1] = (String) idpf.get("Name");
    arglist1[0] = str_grp;

    // idpr is my new selection of Shape
    IDispatch idpr = (IDispatch)((IDispatch)sheet.get("Shapes")).get("Range",arglist1);

    // idp is my new group of shape
    IDispatch idp = (IDispatch) idpr.method("Group",null);

    Thank you for any answer.

     
    • Nobody/Anonymous

      A good trick is to use Excel macro recorder to figure out what the synatx should be.
      In that case I get:
      ActiveSheet.Shapes.Range(Array("Text Box 2", "Text Box 3")).Select
      Selection.ShapeRange.Group.Select

      Are you sure that the naem of your text boxes is name?
      Also are you doing the selection?

      I dunno much about Excel, but that would be where I would be looking...

       
    • Nobody/Anonymous

      The names are correct, I checked them.
      I don't need to do the selection because.

      ActiveSheet.Shapes.Range(Array("Text Box 2", "Text Box 3")).Select
      Selection.ShapeRange.Group.Select

      is doing the same as :
      ActiveSheet.Shapes.Range(Array("Text Box 2", "Text Box 3")).Group.Select

      The problem is that the arglist doesn't seem to have 2 elements. When I call the propertie "Count" on my selection of shape I always retrieved 1.

      In fact, i don't know how to do an "Array" object with multiple arguments to pass in my arglist. When i try this with one shape i have an error because i can't use the method "Group" on a single shape but i can select this particular shape in the ShapeRange.

      IDispatch idpt = (IDispatch)((IDispatch)sheet.get("Shapes")).method("AddTextbox",arglist);

      // argument of the propertie "Range"
      str_grp[0] = (String) idpt.get("Name");
      arglist1[0] = str_grp;

      // idpr is my new selection of Shape
      // idpr is a ShapeRange
      IDispatch idpr = (IDispatch)((IDispatch)sheet.get("Shapes")).get("Range",arglist1);

      arglist1[0] = new Integer(1);
      // idp is my shape
      IDispatch idp = (IDispatch)idpr.method("Item",arglist1);

      // With this code we have idp = idpt..

      Thanks for your answer.
      If you have any other tip i'll be glad to read it.

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks