Quantcast
Channel: General Office Development forum
Viewing all articles
Browse latest Browse all 2257

Powerpoint interop with C# - trouble accessing slide shapes

$
0
0

I am using Visual Studio Community and have added a reference to the Microsoft.Office.Interop.Powerport COM library to my project. I am not developing a VSTO application but want to create and modify a PowerPoint file suing data from my application. I am able to successfully create a new presentation and add a slide to it by copying the slide from another PowerPoint file. That slide contains some Shapes that I need to modify. I have tried to access the shapes one at a time with various methods. In what follows PPT = Microsoft.Office.Interop.PowerPoint

  I've tried

            System.Collections.IEnumerator e = theSlide.Shapes.GetEnumerator();
            while (e.MoveNext())
            {
                PPT.Shape aShape = (PPT.Shape)e.Current;
            }

I get an error that I cannot cast a _com object to PPT.Shape object on the e.Current line. I've tried

            for (int i = 1; i <= theSlide.Shapes.Count; i++)
            {
                PPT.Shape aShape = theSlide.Shapes[i];
            }
where I get an 'object not found' error on the reference to Shapes[i]. When I use the debugger to look at Slides, I see the Count=2, but there does not appear to be any actual collection associated with it. Also, the Item attribute is not visible, even through it is letting me use the [] shorthand.

I have also tried 'foreach' where I get a cast error like the use of e enumerator.


Viewing all articles
Browse latest Browse all 2257

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>