Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

This operation failed because one or more changes made during events were invalid

I am creating a PowerPoint 2010 Add-in using c# in VS 2012. I am inserting an XML file in each presentation. This XML has some important slide related data that must be read after a new presentation is opened. I am adding my custom XML the following way.

Office.CustomXMLPart xmlPart;

string xmlString = "<?xml version='1.0' ?>" +
                            "<data xmlns:c='charts'>" +
                                "<c:Chart>" +
                                    "<c:ChartType>MyChartType</c:ChartType>" +
                                    "<c:ChartID>" + pShape.Id + "</c:ChartID>" +
                                "</c:Chart>" +
                            "</data>";

xmlPart = presentation.CustomXMLParts.Add(xmlString, missing);

Now, I have to read this custom XML whenever a new presentation is open and check whether the ChartType = "MyChartType". Here is the code of the AfterPresentationOpen event.

void pptAPP_AfterPresentationOpen(PowerPoint.Presentation Pres)
{
    foreach (PowerPoint.Shape shapeItem in Pres.Windows[1].Selection.SlideRange.Shapes)
    {
        if (shapeItem.HasChart == Office.MsoTriState.msoTrue)
        {
            **customXMLPart = Pres.CustomXMLParts[0]**; //My XML is at this index
            customXMLNode = customXMLPart.SelectSingleNode("//Chart/ChartType");
        }
    }
}

On theory this should work fine. But when I run the code, the compiler gives me This operation failed because one or more changes made during events were invalid. exception at the ** line.

Update: On running the code with Pres.CustomXMLParts[1], Pres.CustomXMLParts[2] etc, there is no such exception.

like image 436
Zunair Zubair Avatar asked Oct 15 '25 10:10

Zunair Zubair


1 Answers

this is an old post, but I got here when googleing the same error message. after reading this post it hit me, excel has the way of using 1 as the first index, and not the zero-based indexing that we all know and love :).

so, in your update you mention that running the code with Pres.CustomXMLParts[1] and Pres.CustomXMLParts[2] works, because you are using indexes above 0.

your chart data should be in one of those parts.

like image 116
mvgucht Avatar answered Oct 18 '25 05:10

mvgucht



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!