0
votes

I created 3 smartart shapes, and put them into the folder: "C:\Users...\AppData\Roaming\Microsoft\Templates\SmartArt Graphics", and the PowerPoint load them successfully. You can call them from the UI, however if at the beginning once the PowerPoint is opened, and I add a smartart shape into slide programmatically, I always get the following error:

"The index into specified collection is out of bounds"

However If I add my smartart shape from UI first, there is no error if I want to add my smartart shape from code after that.

My smartart shapes: smartart resources

My code is:

Microsoft.Office.Core.SmartArtLayout myLayout = null;
try 
{
       myLayout = PowerPointApp.SmartArtLayouts["SmartArtABS3"];
}
catch (Exception ex)
{
        MessageBox.Show(ex.Message);
        questionLayout = null;
}                

if (questionLayout != null)
{
        PowerPoint.Shape smShape = allShapes.AddSmartArt(myLayout, left, top, width, height);

//.....

}

Note: I am using VS Ultimate 2013, PowerPoint 2013, C#, Add-In-Express

1

1 Answers

0
votes

Pretty sure you cannot use the Name as the Index you must use the Index (Long)

If you don't know it loop through the names till you find a match to find it.