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
 
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

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.
 
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/
 

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

Similar Threads


Top