Powerpoint - cannot select certain shapes by their name

B

Bourgui

Hi all,

I have a weird problem in a Powerpoint macro: certain shapes cannot be
selected by their name, only by their index (and I have verified the name is
correct).

So for example, if the first shape on the first slide is called "Rectangle
1", trying to assign:

Set myShape = ActivePresentation.Slides(1).Shapes("Rectangle 1")

will not work, instead I get an error stating "The item with the specified
name wasn't found"

Just to make sure it isn't a spelling problem (even though I don't actually
type the name, I use variables that store them), I tried something like:

MsgBox
ActivePresentation.Slides(1).Shapes(ActivePresentation.Slides(1).Shapes(1).Name).Name

and got the same error!

It only happens rarely, the shapes are not necessarily of the same type. If
it can help, all the ones I have encountererd so far are placeholders.

I am not the creator of the presentations, so I don't know if anything
special has been done to them (I don't notice anything particular).

If needed I can provide a sample file.


Thanks for your help.

Bourgui
 
S

Steve Rindsberg

Hi all,

I have a weird problem in a Powerpoint macro: certain shapes cannot be
selected by their name, only by their index (and I have verified the name is
correct).

So for example, if the first shape on the first slide is called "Rectangle
1", trying to assign:

Set myShape = ActivePresentation.Slides(1).Shapes("Rectangle 1")

will not work, instead I get an error stating "The item with the specified
name wasn't found"

Just to make sure it isn't a spelling problem (even though I don't actually
type the name, I use variables that store them), I tried something like:

MsgBox
ActivePresentation.Slides(1).Shapes(ActivePresentation.Slides(1).Shapes(1).Name).Name

and got the same error!

It only happens rarely, the shapes are not necessarily of the same type. If
it can help, all the ones I have encountererd so far are placeholders.

I am not the creator of the presentations, so I don't know if anything
special has been done to them (I don't notice anything particular).

If needed I can provide a sample file.

Thanks for your help.

Bourgui


PowerPoint doesn't allow multiple shapes with the same name on a slide.

PowerPoint itself sometimes CREATES additional shapes with the same name on a slide,
then doesn't quite know how to cope with them. Attempts to rename the shape will fail,
for example.

The same thing might be going in in your slide.

Try this:

Dupe the slide so you can work on a copy.

Press TAB to select the first shape on the slide, then delete it.
Try to reference Rectangle 1 again.
Repeat until all shapes are gone or you're successfully able to reference the shape.

Another approach that'll probably clean up the entire presentation is "roundtripping"
it.

HTML "Round-tripping" to repair corruption
http://www.pptfaq.com/FAQ00526.htm
 
B

Bourgui

Thanks Steve,

Round-tripping does indeed solve the problem.
It is not really anything I can use in my case, but I may be able to use
this to develop a method that can be used automatically when required.

Thanks again,

Bourgui
 
S

Steve Rindsberg

Thanks Steve,

Round-tripping does indeed solve the problem.
It is not really anything I can use in my case, but I may be able to use
this to develop a method that can be used automatically when required.

I've toyed with doing something similar in one or two of our add-ins.

For example it'd be fairly quick to iterate through all the shapes in a presentation
"touching" .Name or some other property you know will throw an error if the file's
corrupted. Trap the error and do the roundtrip.
 
B

Bourgui

That's what I did at first, but it wasn't very practical in my situation
(this would interrupt user interaction with the presentation).

I just tried to simply rename the shape, and this seems to 'fix' the
referencing problem. I'm going to use that for now. Next I'll try to rename
it twice, in order to bring it back to its original name, just in case one of
our clients needs to keep the original shape names.

Now, whenever the file is treated completely automatically, I roundtrip the
presentation just in case. I'll test it of course, but so far I haven't had
any problems.
 
S

Steve Rindsberg

That's what I did at first, but it wasn't very practical in my situation
(this would interrupt user interaction with the presentation).

I just tried to simply rename the shape, and this seems to 'fix' the
referencing problem. I'm going to use that for now. Next I'll try to rename
it twice, in order to bring it back to its original name, just in case one of
our clients needs to keep the original shape names.

If it's really the case that there were two shape with the same name in the first place, PPT
won't allow you to rename the shape back to its original (duplicated) name.
 

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