Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 144
Default Problem renaming command buttons with code

Hi all,

I have an issue where data is copied and pasted from an email into a sheet
where the data must be pasted in as Paste All -- the issue is that there are
objects of some sort that get pasted in also. When the code executes, I want
to have the objects (which get pasted in with the names "AutoShape 2544",
"AutoShape 2545", etc.) deleted.

The problem is that I have two command buttons from the Control Toolbox on
the sheet so if I use the code below, the command buttons also get deleted.
Any idea on how I can select all shapes but the two command buttons (Names
"CommandButton1" and "CommandButton2")?

Sheets("Sheet1").Activate
Shapes.SelectAll
Selection.Delete

Thanks,

--
Robert
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Problem renaming command buttons with code

For Each shp In ActiveSheet.Shapes
If shp.ID = 2544 Then
shp.Delete
End If

Next shp


"robs3131" wrote:

Hi all,

I have an issue where data is copied and pasted from an email into a sheet
where the data must be pasted in as Paste All -- the issue is that there are
objects of some sort that get pasted in also. When the code executes, I want
to have the objects (which get pasted in with the names "AutoShape 2544",
"AutoShape 2545", etc.) deleted.

The problem is that I have two command buttons from the Control Toolbox on
the sheet so if I use the code below, the command buttons also get deleted.
Any idea on how I can select all shapes but the two command buttons (Names
"CommandButton1" and "CommandButton2")?

Sheets("Sheet1").Activate
Shapes.SelectAll
Selection.Delete

Thanks,

--
Robert

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 144
Default Problem renaming command buttons with code

Thanks Joel! Since the IDs of the shapes will be different each time data is
pasted into the sheet (it's an input sheet), I changed your code slightly so
that if the name of the shape is different from both of the cmd buttons
(which I renamed) then the shape is deleted. It worked perfectly. Thanks
again!


Sheets("Sheet1").Activate

For Each shp In ActiveSheet.Shapes
If shp.Name < "cmdreturn" And shp.Name < "cmdsubdel" Then
shp.Delete
End If

Next shp

--
Robert


"Joel" wrote:

For Each shp In ActiveSheet.Shapes
If shp.ID = 2544 Then
shp.Delete
End If

Next shp


"robs3131" wrote:

Hi all,

I have an issue where data is copied and pasted from an email into a sheet
where the data must be pasted in as Paste All -- the issue is that there are
objects of some sort that get pasted in also. When the code executes, I want
to have the objects (which get pasted in with the names "AutoShape 2544",
"AutoShape 2545", etc.) deleted.

The problem is that I have two command buttons from the Control Toolbox on
the sheet so if I use the code below, the command buttons also get deleted.
Any idea on how I can select all shapes but the two command buttons (Names
"CommandButton1" and "CommandButton2")?

Sheets("Sheet1").Activate
Shapes.SelectAll
Selection.Delete

Thanks,

--
Robert

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code for Command Buttons Ayman Excel Discussion (Misc queries) 1 November 3rd 08 08:37 PM
VBA code to find macros associated with command buttons in an s/s [email protected] Excel Programming 2 January 16th 08 07:42 PM
Changing Control Object Name( command buttons etc ) from VBA code TONY Excel Programming 1 November 29th 07 06:40 AM
Renaming Worksheet Command Buttons Alan Beban Excel Programming 1 July 31st 07 06:34 PM
Command buttons and code - help!! Lindsey M Excel Programming 1 March 27th 05 09:34 PM


All times are GMT +1. The time now is 04:42 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"