run-time error in powerpoint

B

Brett Ellingson

Hello all,

Sorry for such a long, long post.

I have a problem with a macro that was created based on code from this
faq:
http://www.rdpslides.com/pptfaq/FAQ00326.htm
This set of code is below called the FIRST SET OF CODE

The second set of code is similar but instead of grouping or
ungrouping, it simply selects the OLE object of each slide so that the
data from an open excel spreadsheet is updated.


*********************FIRST SET OF CODE************
Dim oSlides As Slides
Dim oSld As Slide
Dim oShapes As Shapes
Dim oShp As Shape
Dim oShapeRange As ShapeRange
Dim oLineShp As Shape
Dim oEmbedShp As Shape
Dim oEmbedShpName As String
Dim i As Integer
Dim oGroupOrUngroup As Boolean
oGroupOrUngroup = False

Set oSlides = ActiveWindow.Presentation.Slides
For Each oSld In oSlides
ActiveWindow.View.GotoSlide Index:=oSld.SlideIndex
Set oShapes = oSld.Shapes
For Each oShp In oShapes
If oShp.Type = msoLine And oShp.Line.ForeColor.RGB =
16777215 Then
Set oLineShp = oShp
End If
If oShp.Type = msoEmbeddedOLEObject Then
Set oEmbedShp = oShp
oEmbedShpName = oShp.Name
End If
If oShp.Type = msoGroup Then
For i = 1 To oShp.GroupItems.Count
If oShp.GroupItems(i).Type = msoEmbeddedOLEObject
Then
Set oShapeRange = oShp.Ungroup
Exit For
End If
Next i
End If
Next oShp
If oEmbedShpName <> "" Then
******Set oShapeRange =
ActiveWindow.Selection.SlideRange.Shapes.Range _
(Array(oEmbedShp.Name, oLineShp.Name))
oShapeRange.Group.Select
End If
oEmbedShpName = ""
Next oSld

Set oSlides = ActiveWindow.Presentation.Slides
For Each oSld In oSlides
ActiveWindow.View.GotoSlide Index:=oSld.SlideIndex
Set oShapes = oSld.Shapes
For Each oShp In oShapes
If oShp.Type = msoGroup Then
For i = 1 To oShp.GroupItems.Count
If oShp.GroupItems(i).Type = msoEmbeddedOLEObject
Then

ActiveWindow.Selection.SlideRange.Shapes(oShp.Name).Select
ActiveWindow.Selection.ShapeRange.ZOrder
msoSendToBack
oGroupOrUngroup = True
Exit For
End If
Next i
End If
Next oShp
Next oSld

ActiveWindow.View.GotoSlide Index:=1

If oGroupOrUngroup Then
MsgBox ("You have just groupped the worksheets. Have a good
day!")
Else
MsgBox ("You have just ungroupped the worksheets and they are
ready for updating. Have a good day!")
End If

End Sub

*******************************SECOND SET OF CODE******************

Sub Update()
Dim Response

Response = MsgBox("Are all your Excel files for updating your
charts open?", vbYesNo + vbDefaultButton1)

If Response = vbNo Then
Exit Sub
End If

Dim oSlides As Slides
Dim oSld As Slide
Dim oShapes As Shapes
Dim oShp As Shape
Dim oShapeRange As ShapeRange
Dim oUpdate As Boolean

Set oSlides = ActiveWindow.Presentation.Slides
For Each oSld In oSlides
ActiveWindow.View.GotoSlide Index:=oSld.SlideIndex
Set oShapes = oSld.Shapes
For Each oShp In oShapes
If oShp.Type = msoEmbeddedOLEObject Or oShp.Type =
msoLinkedOLEObject Then
oUpdate = True
*****ActiveWindow.Selection.SlideRange.Shapes(oShp.Name).Select
ActiveWindow.Selection.ShapeRange.OLEFormat.DoVerb
Index:=1
ActiveWindow.Selection.Unselect
End If
Next oShp
Next oSld

ActiveWindow.View.GotoSlide Index:=1

If oUpdate = True Then
MsgBox ("The charts are updated!")
Else
MsgBox ("The charts have not been updated. Did you remember
to ungroup them?")
End If

End Sub


I've had this problem for about a month and a half and have read and
read faq's, newsgroup posting, help files on powerpoint and have had
no luck yet. The problem is that I get the following error:

**********************************
run-time error '=-2147024809 (80070057)':

The item with the specified name wasn't found.
*********************************

When I debug the code, it takes me to the following places that I
marked on the above code with asterisks in front of the line that
seems to give the error.

What is weird is that the errors are not consistent. The powerpoint
files have 72 or so slides in them and sometimes the macro will go
through the ppt with no problem or sometimes, it will do the first few
slides.

I've found a work-around that seems to work. Whatever slide that the
macro stops on, I select that slide, do a cut and paste of it into the
exact same location and then it seems to work fine. Then what I do is
go back to the first slide, select the slide and run the macro again,
then it will run fine at least up until it gets past the slide I just
copied and pasted. Then it will either keep going and running fine or
it will stop again on another seemingly random slide. If I cut and
past that slide and run the macro again it will run fine until it hits
the next slide just past the one I fixed a second ago. As a note, I
only use this work around on the update macro, because if the grouping
macro gets and error, I have to go back and manually ungroup or
regroup the stuff.


Does anyone have an idea of how to help solve this problem? Feel free
to e-mail me back at the e-mail address too and hopefully this is
clear as mud, if you need more of an explanation please let me know.

Brett Ellingson
 
S

Steve Rindsberg

Great explanation of the problem. Thanks for the detail.

You remember what they say about "power corrupts"? Well, sometimes PowerPoint
does too. ;-) You're not allowed to have multiple shapes on a slide with the
same name, but PowerPoint will sometimes create them just the same.

I've not heard of this causing problems when using PPT normally, poking it with
the mouse and such, but have a fair number of scars from when it goes into a
tizzy when running VBA that tries to touch a shape's name.

Sometimes copy/pasting the shape or slide sorts things out, as you've found.

Roundtripping the presentation out to HTML and back usually seems to clear up
problems with corrupt names; it's easier to do a wholesale fix this way.


Brett Ellingson said:
Hello all,

Sorry for such a long, long post.

I have a problem with a macro that was created based on code from this
faq:
http://www.rdpslides.com/pptfaq/FAQ00326.htm
This set of code is below called the FIRST SET OF CODE

The second set of code is similar but instead of grouping or
ungrouping, it simply selects the OLE object of each slide so that the
data from an open excel spreadsheet is updated.

*********************FIRST SET OF CODE************
Dim oSlides As Slides
Dim oSld As Slide
Dim oShapes As Shapes
Dim oShp As Shape
Dim oShapeRange As ShapeRange
Dim oLineShp As Shape
Dim oEmbedShp As Shape
Dim oEmbedShpName As String
Dim i As Integer
Dim oGroupOrUngroup As Boolean
oGroupOrUngroup = False

Set oSlides = ActiveWindow.Presentation.Slides
For Each oSld In oSlides
ActiveWindow.View.GotoSlide Index:=oSld.SlideIndex
Set oShapes = oSld.Shapes
For Each oShp In oShapes
If oShp.Type = msoLine And oShp.Line.ForeColor.RGB =
16777215 Then
Set oLineShp = oShp
End If
If oShp.Type = msoEmbeddedOLEObject Then
Set oEmbedShp = oShp
oEmbedShpName = oShp.Name
End If
If oShp.Type = msoGroup Then
For i = 1 To oShp.GroupItems.Count
If oShp.GroupItems(i).Type = msoEmbeddedOLEObject
Then
Set oShapeRange = oShp.Ungroup
Exit For
End If
Next i
End If
Next oShp
If oEmbedShpName <> "" Then
******Set oShapeRange =
ActiveWindow.Selection.SlideRange.Shapes.Range _
(Array(oEmbedShp.Name, oLineShp.Name))
oShapeRange.Group.Select
End If
oEmbedShpName = ""
Next oSld

Set oSlides = ActiveWindow.Presentation.Slides
For Each oSld In oSlides
ActiveWindow.View.GotoSlide Index:=oSld.SlideIndex
Set oShapes = oSld.Shapes
For Each oShp In oShapes
If oShp.Type = msoGroup Then
For i = 1 To oShp.GroupItems.Count
If oShp.GroupItems(i).Type = msoEmbeddedOLEObject
Then

ActiveWindow.Selection.SlideRange.Shapes(oShp.Name).Select
ActiveWindow.Selection.ShapeRange.ZOrder
msoSendToBack
oGroupOrUngroup = True
Exit For
End If
Next i
End If
Next oShp
Next oSld

ActiveWindow.View.GotoSlide Index:=1

If oGroupOrUngroup Then
MsgBox ("You have just groupped the worksheets. Have a good
day!")
Else
MsgBox ("You have just ungroupped the worksheets and they are
ready for updating. Have a good day!")
End If

End Sub

*******************************SECOND SET OF CODE******************

Sub Update()
Dim Response

Response = MsgBox("Are all your Excel files for updating your
charts open?", vbYesNo + vbDefaultButton1)

If Response = vbNo Then
Exit Sub
End If

Dim oSlides As Slides
Dim oSld As Slide
Dim oShapes As Shapes
Dim oShp As Shape
Dim oShapeRange As ShapeRange
Dim oUpdate As Boolean

Set oSlides = ActiveWindow.Presentation.Slides
For Each oSld In oSlides
ActiveWindow.View.GotoSlide Index:=oSld.SlideIndex
Set oShapes = oSld.Shapes
For Each oShp In oShapes
If oShp.Type = msoEmbeddedOLEObject Or oShp.Type =
msoLinkedOLEObject Then
oUpdate = True
*****ActiveWindow.Selection.SlideRange.Shapes(oShp.Name).Select
ActiveWindow.Selection.ShapeRange.OLEFormat.DoVerb
Index:=1
ActiveWindow.Selection.Unselect
End If
Next oShp
Next oSld

ActiveWindow.View.GotoSlide Index:=1

If oUpdate = True Then
MsgBox ("The charts are updated!")
Else
MsgBox ("The charts have not been updated. Did you remember
to ungroup them?")
End If

End Sub

I've had this problem for about a month and a half and have read and
read faq's, newsgroup posting, help files on powerpoint and have had
no luck yet. The problem is that I get the following error:

**********************************
run-time error '=-2147024809 (80070057)':

The item with the specified name wasn't found.
*********************************

When I debug the code, it takes me to the following places that I
marked on the above code with asterisks in front of the line that
seems to give the error.

What is weird is that the errors are not consistent. The powerpoint
files have 72 or so slides in them and sometimes the macro will go
through the ppt with no problem or sometimes, it will do the first few
slides.

I've found a work-around that seems to work. Whatever slide that the
macro stops on, I select that slide, do a cut and paste of it into the
exact same location and then it seems to work fine. Then what I do is
go back to the first slide, select the slide and run the macro again,
then it will run fine at least up until it gets past the slide I just
copied and pasted. Then it will either keep going and running fine or
it will stop again on another seemingly random slide. If I cut and
past that slide and run the macro again it will run fine until it hits
the next slide just past the one I fixed a second ago. As a note, I
only use this work around on the update macro, because if the grouping
macro gets and error, I have to go back and manually ungroup or
regroup the stuff.

Does anyone have an idea of how to help solve this problem? Feel free
to e-mail me back at the e-mail address too and hopefully this is
clear as mud, if you need more of an explanation please let me know.

Brett Ellingson

--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Featured Presenter, PowerPoint Live 2004
October 10-13, San Diego, CA www.PowerPointLive.com
================================================
 
B

Brett Ellingson

Steve,

Thanks man!! Saving it as a web page then re-saving as a presentation
worked great, I've tried it twice and it's worked good so far.

Can you please explain a little more about the shapes' names being
changed and even how to look at those. I'm just curious about the why
of it happening. I read a little about the NAME property and from what
you said it seems like powerpoint will give the same name to 2
different shapes on the same slide. Then when the macro is run, it
"freaks out" because there are 2 shapes with the same name. Is this
right?

I'm not too concerned with the why, the fact that this works is the
best part.

Thanks for the response and the hard work.

Brett
 
D

David M. Marcovitz

S

Steve Rindsberg

Thanks man!! Saving it as a web page then re-saving as a presentation
worked great, I've tried it twice and it's worked good so far.

This the portion of our program where we both face Bombay, bow deeply and say
"Shyam, You Da Man". He taught me this one, bless him.
Can you please explain a little more about the shapes' names being
changed and even how to look at those.

How to look:

Sub ShowNameOfSelectedShape()
MsgBox ActiveWindow.Selection.ShapeRange(1).Name
End Sub

or

Sub TellAll()
Dim oSh as Shape
For Each oSh in ActiveWindow.Selection.SlideRange(1).Shapes
Debug.Print oSh.Name
Next oSho
End Sub
of it happening. I read a little about the NAME property and from what
you said it seems like powerpoint will give the same name to 2
different shapes on the same slide. Then when the macro is run, it
"freaks out" because there are 2 shapes with the same name. Is this
right?

That's about it. PPT's a bit bi-polar about names. Each shape has a name but it
also has a name property, which isn't really the same. For example if you add a
new rectangle to a slide, PPT may assign it the name "Rectangle 3"

You can refer to it by that name, a la

ActivePresentation.Slides(1).Shapes("Rectangle 3") and change its properties

You might do:

ActivePresentation.Slides(1).Shapes("Rectangle 3").Name = "BillGates"

So now you can do:

ActivePresentation.Slides(1).Shapes("BillGates") and change its properties

But the REAL name of the shape is still "Rectangle 3" as far as PPT's concerned.

So suppose you create another shape and try to name it "Rectangle 3" (having
renamed the original one to something else, you think).

PPT's gonna pitch a fit.

Or suppose you copy BillGates. PPT lets you, but since it thinks the name you gave
it is a property, not the real name, it also copies the name to the new shape.

Now you've got several shapes whose names are "BillGates" but since you can only
have one Bill Gates (there isnt' enough money to have two) things get weird from
there pretty fast.



Thanks for the response and the hard work.

You're very welcome.
Brett

Steve Rindsberg <[email protected]> wrote in message

--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Featured Presenter, PowerPoint Live 2004
October 10-13, San Diego, CA www.PowerPointLive.com
================================================
 
D

David M. Marcovitz

But the REAL name of the shape is still "Rectangle 3" as far as PPT's
concerned.

So suppose you create another shape and try to name it "Rectangle 3"
(having renamed the original one to something else, you think).

PPT's gonna pitch a fit.

Steve,

So does this mean that you should never name a shape anything that
PowerPoint might automatically name a shape (such as "Picture 1" or
"AutoShape 7" or "Rectangle 3" because PowerPoint might already have a
shape with that REAL name, and it might name a shape with that name in
the future?

--David

--
David M. Marcovitz, Ph.D.
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPowerPoint/
 
S

Shyam Pillai

David,
A simple test will illustrate the problem:
1. Create a new presentation.
2. Draw an autoshape rectangle on it. Check then name - it will be something
like 'Rectangle 4'
3. Rename the shape to 'Rectangle 5'
4. Now draw another rectangle autoshape. check the names.

You will have 2 shapes with the same name.
 
S

Steve Rindsberg

So does this mean that you should never name a shape anything that
PowerPoint might automatically name a shape (such as "Picture 1" or
"AutoShape 7" or "Rectangle 3" because PowerPoint might already have a
shape with that REAL name, and it might name a shape with that name in
the future?

Good questions - I don't know the answer for certain but I'd say it'd certainly
be prudent to avoid stepping on PPToes with our shape names.


--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Featured Presenter, PowerPoint Live 2004
October 10-13, San Diego, CA www.PowerPointLive.com
================================================
 
S

Steve Rindsberg

David,
A simple test will illustrate the problem:
1. Create a new presentation.
2. Draw an autoshape rectangle on it. Check then name - it will be something
like 'Rectangle 4'
3. Rename the shape to 'Rectangle 5'
4. Now draw another rectangle autoshape. check the names.

You will have 2 shapes with the same name.

Or to make it more confusing, you'll have

One shape whose name is Rectangle 4 and whose .Name property is Rectangle 5
One shape whose name is Rectangle 5 and whose .Name property is Rectangle 5

You might even be able to change the second shape's name property to Rectangle
4 w/o PPT howling.

This has the makings of a great Abbot and Costello routine, no? "Who's on
(Rectangle) First?" ;-)




--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Featured Presenter, PowerPoint Live 2004
October 10-13, San Diego, CA www.PowerPointLive.com
================================================
 
D

David M. Marcovitz

Or to make it more confusing, you'll have

One shape whose name is Rectangle 4 and whose .Name property is
Rectangle 5 One shape whose name is Rectangle 5 and whose .Name
property is Rectangle 5

You might even be able to change the second shape's name property to
Rectangle 4 w/o PPT howling.

This has the makings of a great Abbot and Costello routine, no?
"Who's on (Rectangle) First?" ;-)

So where is this "real" name stored if I can't access it with the .name
property?
--David

--
David M. Marcovitz, Ph.D.
Director of Graduate Programs in Educational Technology
Loyola College in Maryland
Author of _Powerful PowerPoint for Educators_
http://www.loyola.edu/education/PowerfulPowerPoint/
 
S

Steve Rindsberg

So where is this "real" name stored if I can't access it with the .name
property?

Stored? Somewhere in the PPT file. <g>
You can see it in Custom Animation though ... PPT shows you the "real" name
it's assigned, not the .Name property.


--
Steve Rindsberg, PPT MVP
PPT FAQ: www.pptfaq.com
PPTools: www.pptools.com
================================================
Featured Presenter, PowerPoint Live 2004
October 10-13, San Diego, CA www.PowerPointLive.com
================================================
 

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