VBA command to select slide

  • Thread starter Thread starter ben
  • Start date Start date
B

ben

I 'd like to automate a task that goes through all my
slides in turn to delete the existing image on it and
replace it with an updated image from file. The macro
recorder produced the following code:

ActiveWindow.Selection.SlideRange.Shapes("Picture
119").Select
ActiveWindow.Selection.Cut
ActiveWindow.Selection.SlideRange.Shapes.AddPicture
(FileName:="C:\WebCharts\Brent.png",LinkToFile:=msoFalse).
Select

How can I amend this to replace "ActiveWindow" with the
name of the slide in question and how do I
replace "Picture 119" with a generic term so that it
always refers to whatever image happens to be in that
slide
Thank you
 
Ben,
I have sample VBA code to iterate through all slides in a presentation
and all shapes on each slide on my web site.

http://reillyand.com/Support Pages/sub_iterate.htm

You'd want to modify it where it tells you to modify to do what you
are specifically looking for.

It should get you started.

Brian Reilly, PowerPoint MVP
 
ActiveWindow.Selection.SlideRange.Shapes("Picture
119").Select
ActiveWindow.Selection.Cut
ActiveWindow.Selection.SlideRange.Shapes.AddPicture
(FileName:="C:\WebCharts\Brent.png",LinkToFile:=msoFalse).
Select

How can I amend this to replace "ActiveWindow" with the
name of the slide in question and how do I
replace "Picture 119" with a generic term so that it
always refers to whatever image happens to be in that
slide

Generically, this will delete the shape named MyShape on Slide 42

ActivePresentation.Slides(42).Shapes("MyShape").Delete

Or to make it more generic, use variables:

Dim lIndex as Long
Dim sShapeName as String

ActivePresentation.Slides(lIndex).Shapes(sShapeName).Delete

The trick is figuring out what shape to delete. To do that, you'll want to
give the picture a name to begin with so you can use it in the vba scrap above.

Use this to name shapes:

Sub NameIt()
Dim sResponse As String

With ActiveWindow.Selection.ShapeRange(1)
sResponse = InputBox("Rename this shape to ...", "Rename Shape", .Name)
Select Case sResponse
' blank names not allowed
Case Is = ""
Exit Sub
' no change?
Case Is = .Name
Exit Sub
Case Else
On Error Resume Next
.Name = sResponse
If Err.Number <> 0 Then
MsgBox "Unable to rename this shape"
End If
End Select
End With

End Sub
 
Back
Top