Macro to remove images between range of up to 100 sheets


I have gotten stuck attempting to use a macro to remove all images between range of sheets across multiple workbooks. There are over 100 sheets per workbook but for the sake of this exercise I have simplified the extent of which I want to remove. Obviously I am going to perform this task individually for each workbook and could do with some help finishing my macro.

This is what i have so far.

Sub Picdelete()
    Dim ws As Worksheet
    Dim sh As Shape
    Worksheet = Sheets(Array("Sheet14", "Sheet15", "Sheet16", "Sheet17", "Sheet18"))
    pictop = Selection.Top
    picleft = Selection.Left
    precision = 10   'set to 0 if the pictures are EXACTLY in the same place on each sheet
    For Each ws In Worksheets
      For Each sh In ws.Shapes
        If Abs(sh.Top - pictop) <= precision And Abs(sh.Left - picleft) <= precision Then
        End If
      Next sh
    Next ws
End Sub
Post Edited
CODE Tags: You must add [CODE][/CODE] tags around your code! (click the CODE button to do this when creating a post)


Please don't forget to select the answer that worked best for you! Just click the Select Answer button at the bottom of the desired answer.
don (rep: 1237) Jul 2, '17 at 11:46 am
Add to Discussion



Try this.. [ GIVE CREDIT if this works for you Please!!].

    Make sure to back up first!

Sub RemovePics()
    Dim wb As Workbook
    Dim ws As Worksheet
    Dim p As Object 'pictures
    Set wb = ActiveWorkbook
    Set ws = wb.ActiveSheet
  For Each ws In ActiveWorkbook.Worksheets
    For Each p In ws.Pictures
        'MsgBox p.Name
    Next p
  Next ws
    Set p = Nothing
    Set ws = Nothing
    Set wb = Nothing
    MsgBox "Operation Complete! " & Chr(13) & "All pictures deleted!", vbInformation, "Finished!"
End Sub
Post Edited
CODE Tags: You must add [CODE][/CODE] tags around your code! (click the CODE button to do this when creating a post)


This operation would be applied to all sheets in the active workbook. I need the macro to apply to a select number of sheets (which can be listed or can be a range) only.
Dewbo1234 Jun 26, '17 at 3:29 am
Dim Worksheets as Variant
to the top

And then add:
Worksheets = Array("Sheet1","Sheet3","Etc")

And change:
don (rep: 1237) Jun 26, '17 at 4:19 am
Don't forget the CODE tags queue; I put some in for you so it's easier to read.
don (rep: 1237) Jun 26, '17 at 4:21 am
Add to Discussion

Answer the Question

You must create an account to use the forum. Create an Account or Login