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!

Re: Delete command button, but not other shapes in document by Jay

Jay
Fri Oct 28 22:22:05 CDT 2005

On Fri, 28 Oct 2005 05:12:02 -0700, westis
<westis@discussions.microsoft.com> wrote:

>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

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org