Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2005

Tip: Looking for answers? Try searching our database.

Delete command button, but not other shapes in document

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
westis - 28 Oct 2005 13:12 GMT
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!
Jay Freedman - 29 Oct 2005 04:22 GMT
>Hi,
>
[quoted text clipped - 12 lines]
>
>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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.