PowerPoint VSTO - how to lock Shapes (manually you would do this in the Selection Pane)?

165 Views Asked by At

The following answer explains how to do this in VBA by setting the Locked property on the PowerPoint Shape. However, when trying to do this in C# as a VSTO Addon the Locked property is not available.

2

There are 2 best solutions below

1
Eugene Astafiev On BEST ANSWER

The ShapeRange class doesn't expose the Locked property. If that works in VBA then you may try using the late-binding technology to call hidden or private members. Use the Type.InvokeMember method to make such calls in .net applications.

1
Neil Kimber On

Thanks to @Eugene Astafieve. The following line achieves what I wanted to do:

var LockedVar = myGroup.GetType().InvokeMember("Locked", System.Reflection.BindingFlags.SetProperty, null, myGroup, new object[] { OfficeCore.MsoTriState.msoTrue });

Where: myGroup is a PPT Shape (in my case a Grouped Shape)