Remove images which are behind an image

trustmywords

New Member
Joined
Feb 22, 2011
Messages
9
I want to remove images that are hidden behind an particular image. Can anybody create macro to delete all the hidden images behind main image. No other images must be deleted if other parts of excel has images.

thanks
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Try...

Code:
Option Explicit
 
Sub DeleteHiddenPics()
 
    Dim oMainPic As Picture
    Dim oPic As Picture
    Dim rRng As Range
 
'   Change the name of the picture accordingly
    Set oMainPic = ActiveSheet.Pictures("Picture 1")
 
    Set rRng = Range(oMainPic.TopLeftCell, oMainPic.BottomRightCell)
 
    For Each oPic In ActiveSheet.Pictures
        If oPic.Name <> oMainPic.Name Then
            If oPic.ZOrder < oMainPic.ZOrder Then
                If Application.Union(rRng, Range(oPic.TopLeftCell, oPic.BottomRightCell)).Address = rRng.Address Then
                    oPic.Delete
                End If
            End If
        End If
    Next oPic
 
End Sub
 
Upvote 0
Domenic

ths is the error message i am getting if i run macros.

"unable to get pictures property of the worksheet class"

I dont know to write macro.

Please provide another solution.

thanks
 
Upvote 0
Did you change the name of the main picture specified in the following line?

Code:
Set oMainPic = ActiveSheet.Pictures("[COLOR=red]Picture 1[/COLOR]")
 
Upvote 0

Forum statistics

Threads
1,223,635
Messages
6,173,479
Members
452,516
Latest member
archcalx

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top