Remove background image with VB

UHsoccer

Well-known Member
Joined
Apr 3, 2002
Messages
1,023
I have created a process where I use a background image and then add multiple text in various cells. I do this for about 10 sheets on a regular basis.
When I have to to rerun the process, I have to manually delete the background on each sheet first since the image name increments each time to a new one

Is there a way to simply "remove background image if it exists"
 

Some videos you may like

Excel Facts

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.

patrickmuldoon99

Active Member
Joined
Jun 27, 2006
Messages
345
I don't know the direct code, but surely you could find it out by recording yourself removing the background image.

Then, if there is the possibility that there will be no background image to remove, you can include the line

Code:
on error resume next

after you have included the recorded instruction of removing the background image.


Hope this helps

Patrick
 

UHsoccer

Well-known Member
Joined
Apr 3, 2002
Messages
1,023
When one records the delete of a background it looks like this

ActiveSheet.Shapes("Picture 49").Select
Selection.Delete

The problem is that the actual name "Picture 49" will be "Picture 50" the next time, etc. It is different on each sheet.

I need to find out how the get that name and then substitute that into the select statement
 

patrickmuldoon99

Active Member
Joined
Jun 27, 2006
Messages
345
Ah right, i'm with you.

Well you could iterate through the workbooks shapes collection... are the shapes that are the background the only objects with "Picture" starting the name?

If so, we could iterate through activesheet.shapes and simply delete all images on the sheet.
 

Watch MrExcel Video

Forum statistics

Threads
1,113,811
Messages
5,544,444
Members
410,610
Latest member
renatha prado
Top