This code example shows how to find a button in Microsoft Word in a VSTO Addin and delete it at runtime
A VSTO addin is an Office add-in in Word, Excel, Powerpoint or Outlook, which is created in Visual Studio and can be loaded in the Office application as a COM add-in
C # buttons
In the example application, the button is deleted via the menu bar / Ribbonbar as soon as you want to insert photos.
The macro was built in as a subitem in a VSTO Addin for Word.
At runtime, the macro examines all inline shapes. These are photos but also embedded objects like form buttons or graphics.
If the object corresponds to a Forms.CommandButton, it will be checked for the title and deleted if necessary.
//----< delete button >---- //*delete Photo Button foreach(Word.InlineShape inlineShape in doc.InlineShapes ) { //--< InlineShape >-- if(inlineShape.Type== Word.WdInlineShapeType.wdInlineShapeOLEControlObject) { if(inlineShape.OLEFormat.ClassType.ToString()== "Forms.CommandButton.1") { //--< Button >-- var objButton = inlineShape.OLEFormat.Object; string sTitle=objButton.Caption;
if (sTitle.IndexOf("Fotos") > -1) { //< Delete > inlineShape.ScaleWidth = 1; inlineShape.Delete(); //</ Delete >
break; } //--</ Button >-- }
MessageBox.Show("Word Button"); } //--</ InlineShape >-- } //----</ delete button >----
|
The macro as Word Addin is available for download in my Office Portal.