c# Error with inserting more than one shape group on the slide

0

UPD: Maybe it helps. This is details of my Error:

System.UnauthorizedAccessException HResult=0x80070005
Message=Grouping disabled for selected shapes (Для выделенных фигур группирование отключено). Source=FirstPPTAddIn StackTrace: at Microsoft.Office.Interop.PowerPoint.ShapeRange.Group() at FirstPPTAddIn.MyRibbon.OnShapeButton(IRibbonControl control) in D:\Documents\Visual Studio 2017\Projects\FirstPPTAddIn\FirstPPTAddIn\MyRibbon.cs:line 84

I added my add-in to Exeption Settings and when I've run code for the second group set I got two additional shapes on the slide without grouping. I don't understand why the last line of code doesn't work. I can just "copy-past" the first group set many times and make changes with them, but I need add them by button.


I used this code for grouping shapes. But it allows to put just one shape groups only. What I need to change in code for inserting unlimited shape groups on the one slide?

Part of code

    PowerPoint._Application myPPT = Globals.ThisAddIn.Application;
    PowerPoint.Slide curSlide = myPPT.ActiveWindow.View.Slide;
    string[] myRangeArray = new string[2];
    myRangeArray[0] = "shape1";
    myRangeArray[1] = "shape2";
    curSlide.Shapes.Range(myRangeArray).Group();

When I try to insert second shape group I have an error in the last line says System.UnauthorizedAccessException: "grouping is disabled for selected shapes".

Thanks!

c#
powerpoint
add-in
asked on Stack Overflow Oct 18, 2018 by Lena Kire • edited Oct 23, 2018 by LarsTech

2 Answers

0

That may be due to The file is already in use.Try to manually dump the powerpoint.exe after adding shape 1

An UnauthorizedAccessException can be one of the following reason:

  • The caller does not have the required permission.
  • The file is an executable file that is in use.
  • Path is a directory.
  • Path specified a read-only file.
answered on Stack Overflow Oct 18, 2018 by PrathapG
0

A friend of mine solved this problem today. He add counter for the shapes in Array. The part of code below

private int count = 0;
public void OnButton(Office.IRibbonControl control)
{
     var shape1Name = "shape1" + count;
     var shape2Name = "shape2" + count;
...
     shape1.Name = shape1Name;
     shape2.Name = shape2Name;
...
     string[] myRangeArray = new string[2];
     myRangeArray[0] = (shape1Name);
     myRangeArray[1] = (shape1Name); 
     curSlide.Shapes.Range(myRangeArray).Group(); 
     count++;
}
answered on Stack Overflow Oct 23, 2018 by Lena Kire

User contributions licensed under CC BY-SA 3.0