PowerPoint.Shape "Convert to Shape" in code

232 Views Asked by At

in my Power Point add-in I am loading .svg file within slide using this code

            Slide activeSlide = Globals.ThisAddIn.Application.ActiveWindow.View.Slide;
            PowerPoint.Shape ppPicture = activeSlide.Shapes.AddPicture(testImageUrl, MsoTriState.msoTrue, MsoTriState.msoTrue, 0, 0);
            ppPicture.LinkFormat.SourceFullName = testImageUrl;

then I need to ungroup this file, like it happens when clicking mouse right button and selecting menu point "Convert to Shape".

ppPicture.Ungroup();

throws System.UnauthorizedAccessException: 'This member can only be accessed for a group.'

So how can I do it ?

1

There are 1 best solutions below

0
On

Sorry but can you provide more information? For example what is testImageUrl and bc Shape.LinkFormat is a way to manage OLE object, object linking and embedding, so it would typically be Excel > Powerpoint or Excel > Word if we think of how a normal application would work.

Please note, the SourceFullName property takes on different properties depending if its a table or chart:

table = {file.fullname}!{range.address} or chart = {file.fullname}![{file.name}]{worksheet.name}{chart.name}

It is possible that the file is located on a public server (e.g., OneDrive, SharePoint, Teams, etc.) which in that case it would have a "URL" in the filename but the logic remains the same.

More information would be helpful to understand what you are trying to accomplish. Alternatively, if the object is already in the clipboard you can utilize

var shape = slide.Shapes.PasteSpecial(DataType: PpPasteDataType.ppPasteOLEObject, Link: Microsoft.Office.Core.MsoTriState.msoTrue)[1];

Which would paste and automatically select the shape for you to then try and perform shape.Ungroup().