bottom
Great ExcelTips!
         
Your e-mail address is safe!
Close Note

Tips.Net > ExcelTips Home > Macros > Removing Pictures for a Worksheet in VBA

Removing Pictures for a Worksheet in VBA

Summary: If you are having a problem deleting pictures using a macro, it could be due to either bad syntax or different groupings of the images. This tip discusses both causes and what you can do about them. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, Excel 2003, and Excel 2007.)

Rob wrote about a problem he was having removing pictures from a worksheet. He has macros that add a picture (a signature) as a shape, but when he later tries to delete the picture, he cannot find it in the Shapes collection.

There are a couple of things to check out. First of all, you should ensure that you are using the proper syntax to do the deletion. Check to make sure you are explicitly including the sheet object in your code. For instance, the following line will not work:

Shapes(1).Delete

Instead, you must specify the sheet, using code similar to any of the following lines:

ActiveSheet.Shapes(1).Delete
Sheets("Sheet1").Shapes(1).Delete
Sheets(1).Shapes("Signature").Delete

If you determine that the expected image is not in the Shapes collection, then it is possible that Excel (for strange reasons only known to Excel) moved the image to a different collection, such as the Pictures collection. If you suspect this, then try using the following macro:

Sub WhatAmI()
    Dim sTemp As String

    sTemp = "You selected this type of object: " & TypeName(Selection)
    sTemp = sTemp & vbCrLf
    sTemp = sTemp & "It's name is " & Selection.Name
    MsgBox sTemp
End Sub

Select the signature image, then run the macro. You should see a message box that indicates the type of object you selected, along with its name. You can then use the information to modify your macro so it deletes the image, as desired.

Tip #2480 applies to Microsoft Excel versions: 97 | 2000 | 2002 | 2003 | 2007


Tame Your Data! ExcelTips: Filters and Filtering provides all the details necessary to let you manage large sets of data with confidence and ease. Its information-packed pages demonstrate how to use the two types of filters provided by Excel: AutoFilters and advanced filters.
 
Check out ExcelTips: Filters and Filtering today!

Helpful Links

Ask an Excel Question
Make a Comment

Tips.Net Home

ExcelTips FAQ
ExcelTips Premium

Learn Access Now

Bugs and Pests Tips
ExcelTips
Family Tips
Health Tips
Home Tips
Organizing Tips
WordTips

Advertise on the
ExcelTips Site

 

Great Info!

Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your e-mail address and click "Subscribe."
     
(Your e-mail address will never be shared with anyone, ever.)