Delete Worksheets with a Background

Gary's Student

Well-known Member
Joined
Aug 4, 2012
Messages
1,015
I have a set of workbooks each of which contain many worksheets. I need to examine each sheet and if it contains an applied Background, delete that sheet.

This is easy to do manually, but very tedious. Can it be accomplished with a macro?
 

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
This is easy to do manually, but very tedious.

What does the macro recorder give you? I mean, with almost 1,000 posts here I bet you can use the macro recorder and inspect the coding :)
For instance, record a macro when you apply the background to a sheet, then delete the background again, and stop the recorder.
 
Upvote 0
It doesn't appear that it is exposed in the object model. You can set it, but not read it.
 
Upvote 0
Then it will be a manual job. Or SendKeys ;)
 
Upvote 0
There is no error produced if you try to remove a background that isn't there so just loop through all the sheets e.g.

Code:
Sub Remove_Background()
For Each Sht In Sheets
    Sht.SetBackgroundPicture Filename:=""
Next
End Sub
 
Upvote 0
Stephen: to automate the job, which is now a manual tedious job.
Unless I misunderstood the question from the OP.
 
Upvote 0
@Teeroy: If I understand the original question, the problem is not how to remove the background, but to detect whether the sheet has one.
 
Upvote 0
@Teeroy: If I understand the original question, the problem is not how to remove the background, but to detect whether the sheet has one.

@Shg, you are correct. I missed one word in the first post and ...:oops:.

You can find out if a sheet has a background image by checking the workbook ZIP container to check for a sheet relationships element (e.g. sheet1.xml.rels) but you'd need to programmatically access the internals of the zip container which I've never done; I've only gone in manually to recover information. You probably also need to walk the XML tree to see whether it contains a reference to an image as well.
 
Last edited:
  • Like
Reactions: shg
Upvote 0

Forum statistics

Threads
1,214,375
Messages
6,119,164
Members
448,870
Latest member
max_pedreira

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