Delete command button, but not other shapes in document

W

westis

Hi,

I need a macro to delete a command button, but not other shapes in the
document. How can I delete only the command button? And this must be a
solution that works in several different documents, some with other shapes,
some with the command button being the only shape.

The following code deletes all shapes:

For Each oShp In ActiveDocument.Shapes
oShp.Delete
Next oShp

I understand I must be able to identify the command button somehow.

Thanks!
 
J

Jay Freedman

Hi,

I need a macro to delete a command button, but not other shapes in the
document. How can I delete only the command button? And this must be a
solution that works in several different documents, some with other shapes,
some with the command button being the only shape.

The following code deletes all shapes:

For Each oShp In ActiveDocument.Shapes
oShp.Delete
Next oShp

I understand I must be able to identify the command button somehow.

Thanks!

Dim oShp As Shape

For Each oShp In ActiveDocument.Shapes
With oShp
If .Type = msoOLEControlObject Then
If .OLEFormat.ClassType = "Forms.CommandButton.1" Then
oShp.Delete
End If
End If
End With
Next oShp
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top