How do i find if a shape "xyz" is on Selected slide with vba

C

Chuck [Sbc\)

I am using a macro which scans all of the slides in a presentation to make
changes to a given shape (Named). I would like to know if the selected
slide contains a shape (textbox) with the name of "xyz" If it does, I want
to skip that slide.
 
S

Steve Rindsberg

Chuck [Sbc) said:
I am using a macro which scans all of the slides in a presentation to make
changes to a given shape (Named). I would like to know if the selected
slide contains a shape (textbox) with the name of "xyz" If it does, I want
to skip that slide.

One simple way is to call a function that finds the shape on the slide, if it
exists. It's probably more generally useful than just testing to see if the
shape exists or not; you may want to do something with the shape in other
macros, and the same function can be used to get the shape and work with it.

Say you're in a loop like:

Dim oSl as Slide
Dim oSh as Shape

For each oSl in ActivePresentation.Slides
Set oSh = GetShape(oSl, "xyz") Then
If oSh Is Nothing Then ' no shape by that name
' do your stuff here
End If
Next ' oSl

Function GetShape(oSl as Slide, sShapeName as String) as Shape
' Returns the shape named sShapeName on oSl
' or nothing if the shape doesn't exist
On Error Resume Next
Set GetShape = oSl.Shapes(sShapeName)
End Function
 

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

Top