Selecting image on worksheet and deleting..

  • Thread starter Thread starter groundhog1
  • Start date Start date
G

groundhog1

What's wrong with this code? It won't run. I am trying to select a .bmp
image on my worksheet and delete it. I also have a command button on the
worksheet and don't want to delete that. The button is "Button 55".
Thanks,
groundhog

Sheets("Sheet1").Select
ActiveSheet.Shapes.SelectAll
ActiveSheet.Shapes("Button 55").Deselect
Selection.Delete
 
Give this a try...

Sub RemovePictures()
Dim shp As Shape

For Each shp In ActiveSheet.Shapes
If shp.Name <> "Button 55" Then shp.Delete
Next shp
End Sub
 
Buttons from the forms toolbar do have spaces in them by default when they
are added. Buttons from the control toolbox don't, but you can add them in if
you wish...

Named ranges can not have spaces in them, but objects such as shapes can.

The code that groundhog first posted will crach if Button 55 does not exist,
which is why I choose the route that I did. With the posted code, if button
55 does not exist then it will just delete all of the shapes...
--
HTH...

Jim Thomlinson


Trent Argante said:
Change "Button 55" to "Button55"; controls can't have spaces in their names.
--
Trent Argante
[DC.J(n/a)]


Jim Thomlinson said:
Give this a try...

Sub RemovePictures()
Dim shp As Shape

For Each shp In ActiveSheet.Shapes
If shp.Name <> "Button 55" Then shp.Delete
Next shp
End Sub
 
The one thing I neglected to mention (probably what you are describing) in
the properties for the command button from the control toolbox the "Name" can
not have any spaces in it. In the drop down where you see the current cell
address you can add the space. Why you ever would is a complete mystery but
you can if that is what floats your boat.
--
HTH...

Jim Thomlinson


Jim Thomlinson said:
Buttons from the forms toolbar do have spaces in them by default when they
are added. Buttons from the control toolbox don't, but you can add them in if
you wish...

Named ranges can not have spaces in them, but objects such as shapes can.

The code that groundhog first posted will crach if Button 55 does not exist,
which is why I choose the route that I did. With the posted code, if button
55 does not exist then it will just delete all of the shapes...
--
HTH...

Jim Thomlinson


Trent Argante said:
Change "Button 55" to "Button55"; controls can't have spaces in their names.
--
Trent Argante
[DC.J(n/a)]


Jim Thomlinson said:
Give this a try...

Sub RemovePictures()
Dim shp As Shape

For Each shp In ActiveSheet.Shapes
If shp.Name <> "Button 55" Then shp.Delete
Next shp
End Sub

--
HTH...

Jim Thomlinson


:

What's wrong with this code? It won't run. I am trying to select a .bmp
image on my worksheet and delete it. I also have a command button on the
worksheet and don't want to delete that. The button is "Button 55".
Thanks,
groundhog

Sheets("Sheet1").Select
ActiveSheet.Shapes.SelectAll
ActiveSheet.Shapes("Button 55").Deselect
Selection.Delete
 
I modified your code to print the names of each shape and found out what
you're talking about, and if that's not cunfusing, I don't know what is! It
seems like Excel treats shapes like ranges...
The route you took is the cleanest.
Thanks for the extended explanation - it helped me at least.
--
Trent Argante
[DC.J(n/a)]


Jim Thomlinson said:
The one thing I neglected to mention (probably what you are describing) in
the properties for the command button from the control toolbox the "Name" can
not have any spaces in it. In the drop down where you see the current cell
address you can add the space. Why you ever would is a complete mystery but
you can if that is what floats your boat.
--
HTH...

Jim Thomlinson


Jim Thomlinson said:
Buttons from the forms toolbar do have spaces in them by default when they
are added. Buttons from the control toolbox don't, but you can add them in if
you wish...

Named ranges can not have spaces in them, but objects such as shapes can.

The code that groundhog first posted will crach if Button 55 does not exist,
which is why I choose the route that I did. With the posted code, if button
55 does not exist then it will just delete all of the shapes...
--
HTH...

Jim Thomlinson


Trent Argante said:
Change "Button 55" to "Button55"; controls can't have spaces in their names.
--
Trent Argante
[DC.J(n/a)]


:

Give this a try...

Sub RemovePictures()
Dim shp As Shape

For Each shp In ActiveSheet.Shapes
If shp.Name <> "Button 55" Then shp.Delete
Next shp
End Sub

--
HTH...

Jim Thomlinson


:

What's wrong with this code? It won't run. I am trying to select a .bmp
image on my worksheet and delete it. I also have a command button on the
worksheet and don't want to delete that. The button is "Button 55".
Thanks,
groundhog

Sheets("Sheet1").Select
ActiveSheet.Shapes.SelectAll
ActiveSheet.Shapes("Button 55").Deselect
Selection.Delete
 
Back
Top