VBA: Delete background pic by filename?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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?
 
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.
 
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.
 
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.
 
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:

Change it to this:

Dim oSh as Shape

ActivePresentation.SlideMaster.Shapes("BG").Delete

' watch for wordwrap here:
Set oSh =
ActivePresentation.SlideMaster.Shapes.AddPicture(FileName:="C:\Project\8_paper.jpg",
LinkToFile:=msoFalse, SaveWithDocument:=msoTrue, Left:=36, Top:=27,
Width:=648, Height:=486)

With oSh
.ScaleWidth 1.06, msoFalse, msoScaleFromBottomRight
.ScaleHeight 1.06, msoFalse, msoScaleFromBottomRight
.ScaleWidth 1.05, msoFalse, msoScaleFromTopLeft
.ScaleHeight 1.05, msoFalse, msoScaleFromTopLeft
.ZOrder msoSendToBack
.Name = "BG"
End With
 
Back
Top