Solved Deleting Drawing Objects/Pictures Using Macros

Microsoft Office excel 2003
September 13, 2013 at 13:22:02
Specs: Windows Vista, Pentium 2.6 GHz; 4GB RAM
I am pasting information into Excel and then running a macro to format the information. Unfortunately, sometimes a small gif or two get pasted in and I would like the macro to be able to delete these. I have tried to figure out how but, cannot. When I ran a test the macro does not recognize clicking the Select Objects tool, highlighting the data set and clicking delete.

Any help would be appreciated. Thanks.


See More: Deleting Drawing Objects/Pictures Using Macros

Report •


#1
September 13, 2013 at 13:38:42
The gif's might have become part of the Shapes collection on the sheet.

Single Step through this code via F8 and see if it Selects the items, and only the items, that you want to delete.

If it does, get rid of the .Select line and uncomment the .Delete line.


Sub ShapeNames()
 For Each shp In ActiveSheet.Shapes
  shp.Select
  'shp.Delete
 Next
End Sub

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

#2
September 13, 2013 at 14:10:59
I tried your script and it worked and deleted all objects on the spreadsheet. I used...

Sub ShapeNames()
For Each shp In ActiveSheet.Shapes
shp.Delete
Next
End Sub

But, I want that to work within another macro I have. I did a test macro with script as follows...

Sub TEST()
'
' TEST Macro
' Macro recorded 9/13/2013 by Steve
'

'
Cells.Select
With Selection
.Orientation = 0
.AddIndent = False
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
With Selection.Font
.Name = "Arial"
.Size = 10
.Strikethrough = False
.Superscript = False
.Subscript = False
.OutlineFont = False
.Shadow = False
.Underline = xlUnderlineStyleNone
.ColorIndex = xlAutomatic
End With
Range("A1").Select
End Sub

How do I get yours to work within the one I just recorded?

Thanks!


Report •

#3
September 13, 2013 at 14:37:35
✔ Best Answer
First, a posting tip...

Please click on the blue line at the end of this post and read the instructions on how to post VBA code in this forum.

As far as including the code in your recorded macro, simply copy everything between the Sub and End Sub lines and paste it into your code wherever you want it to run. Just be sure to keep outside of the With-End With sections or you might run into problems.

Click Here Before Posting Data or VBA Code ---> How To Post Data or Code.


Report •

Related Solutions

#4
September 16, 2013 at 07:30:48
Thanks so much for the help. Sorry about the posting of the script. I read the instructions on posting data/code and will do it correctly next time. Thanks so much.

Report •


Ask Question