VBA: Delete background pic by filename?

A

avfc4me

I have the same background pic in several presentations, and I want to
replace that file depending on which button is pressed. The background
picture is called "blank_pic.jpg".

I can do a replace of the item using this:
ActiveWindow.ViewType = ppViewSlideMaster
ActivePresentation.SlideMaster.Shapes("Picture 13").Select
ActiveWindow.Selection.ShapeRange.Delete

ActivePresentation.SlideMaster.Shapes.AddPicture(FileName:="C:\Project\8_paper.jpg",
LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=36, Top:=27,
Width:=648, Height:=486).Select
With ActiveWindow.Selection.ShapeRange
.ScaleWidth 1.06, msoFalse, msoScaleFromBottomRight
.ScaleHeight 1.06, msoFalse, msoScaleFromBottomRight
End With
With ActiveWindow.Selection.ShapeRange
.ScaleWidth 1.05, msoFalse, msoScaleFromTopLeft
.ScaleHeight 1.05, msoFalse, msoScaleFromTopLeft
End With
ActiveWindow.Selection.ShapeRange.ZOrder msoSendToBack
ActiveWindow.ViewType = ppViewSlide


But I'd rather just delete the background image "blank_pic.jpg" rather than
go through all of my presentations and figure out which picture number the
blank is in every presentation. Is it possible?
 
Z

zidansoft

I have the same background pic in several presentations, and I want to
replace that file depending on which button is pressed. The background
picture is called "blank_pic.jpg".

I can do a replace of the item using this:
ActiveWindow.ViewType = ppViewSlideMaster
ActivePresentation.SlideMaster.Shapes("Picture 13").Select
ActiveWindow.Selection.ShapeRange.Delete

ActivePresentation.SlideMaster.Shapes.AddPicture(FileName:="C:\Project\8_paper.jpg",
LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=36, Top:=27,
Width:=648, Height:=486).Select
With ActiveWindow.Selection.ShapeRange
.ScaleWidth 1.06, msoFalse, msoScaleFromBottomRight
.ScaleHeight 1.06, msoFalse, msoScaleFromBottomRight
End With
With ActiveWindow.Selection.ShapeRange
.ScaleWidth 1.05, msoFalse, msoScaleFromTopLeft
.ScaleHeight 1.05, msoFalse, msoScaleFromTopLeft
End With
ActiveWindow.Selection.ShapeRange.ZOrder msoSendToBack
ActiveWindow.ViewType = ppViewSlide

But I'd rather just delete the background image "blank_pic.jpg" rather than
go through all of my presentations and figure out which picture number the
blank is in every presentation. Is it possible?

As far as my knowledge it is not possible at all through automation.
 
K

kraves

avfc4me said:
But I'd rather just delete the background image "blank_pic.jpg" rather than
go through all of my presentations and figure out which picture number the
blank is in every presentation. Is it possible?

Looks like you are inserting a picture as your background and not using the
"Background" option - which is my preference too.

I suggest you make use of the alternate text. Still involves editing each
presentation but not changing the code at all. An idea expressed elsewhere on
this group for similar problems.


Basically right-click on the background picture -> format picture -> Web.
Enter something simple like BG.

Then you just need loop through the shapes until you find .AlternativeText
="BG" - that gives you the shape then off you go and delete/replace etc etc.

Same code for all presentations, provided you edit the text field.

Hope that helps.
 
A

avfc4me

Thanks for the tip!

I ended up deleting the background image all together, then just dropping a
color in there instead; when you "send to back", it ignores the straight
color and drops the image in front of it. Not a perfect solution but it does
seem to be holding up to the testing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top