Simple PowerPoint macro hangs on apparent bug

W

wadiuwant

Hi all

I am looking for help for what should be a simple macro. I'm running
PowerPoint 2003 (XP).

I want to create a macro that will copy a specific rectangle from a
specific slide to the same position on the current slide.

When I use Record New Macro, I get the following:

Sub Copy_Rectangle()
ActiveWindow.Selection.SlideRange.Shapes("Rectangle 48").Select
ActiveWindow.Selection.Copy
ActiveWindow.Selection.Unselect
ActiveWindow.View.Paste
ActiveWindow.Selection.Unselect
End Sub

However when I run the macro, I get a run-time error '-2147024809
(80070057)': The item with the specified name wasn't found and the
debugger shows that the macro stopped on the first line.

This is apparently a known bug. I've looked at Article ID 278575, but
I am unable with my knowledge level to generalise from the example in
that article to my macro. (Also when I hit End the rectangle still
doesn't appear.)

Any help would be appreciated.

Regards
Richard
 
J

John Wilson

It's not really a bug your code just won't work. The macro recorder doesn't
always (often in fact) produce good code. In this instance I guess you've
changed slides while recording but your macro doesn't know this.

If you post exactly what you are trying to do AND WHEN (eg in edit mode or
show mode) then I'm sure you'll get workable code.
--
Amazing PPT Hints, Tips and Tutorials

http://www.PPTAlchemy.co.uk
http://www.technologytrish.co.uk
email john AT technologytrish.co.uk
 
W

wadiuwant

I have a slide which would normally be hidden during the presentation,
on which are the standard boxes, arrows and so forth, that the
presentation writer is to use when making the presentation. On that
slide is a rectangle that would be used for a summary on a displayed
slide. The request is for a macro that will take place the rectangle
on the current slide during the the editing of the presentation. So
yes I did change slides when trying to make the macro, first to the
slide that holds the rectangle so the copy could be made and then to
the "current" slide on which the rectangle is to be displayed.

Regards
Richard
 
J

John Wilson

Change the Slide(3) to whatever slide the rectangle is on and try this
()assuming I've understood)

Sub get_rectangle()
With ActivePresentation.Slides(3).Shapes("Rectangle 48").Copy
ActiveWindow.Selection.SlideRange(1).Shapes.Paste
End Sub

If the slide with the rectangle is going to change you will need to use the
SlideID which won't change when more slides are added

use for example

With ActivePresentation.Slides.FindBySlideID(258).Shapes("Rectangle 48").copy

you can find a slide's ID with

Sub IDfind()
MsgBox ActiveWindow.Selection.SlideRange(1).SlideID
End Sub

--
Amazing PPT Hints, Tips and Tutorials

http://www.PPTAlchemy.co.uk
http://www.technologytrish.co.uk
email john AT technologytrish.co.uk
 
W

wadiuwant

Thanks for all the help.

I'll try to put it in practice tomorrow my time when I get to work.

regards
Richard- Hide quoted text -

- Show quoted text -

I changed the code to

Sub Copy_Rectangle()
With ActivePresentation.Slides(6).Shapes("Rectangle 48").Copy
ActiveWindow.Selection.SlideRange(1).Shapes.Paste
End Sub

When I run thos macro, I get a Compile error: Expected Function or
variable
The word ".Copy" is selected.

Regards
Richard
 
W

wadiuwant

Sorry - slip of the mouse when copying!

Delete the word "With"
--
Amazing PPT Hints, Tips and Tutorials

http://www.PPTAlchemy.co.ukhttp://www.technologytrish.co.uk
email john AT technologytrish.co.uk









- Show quoted text -

Again I say much thanks for your help. And I ask that you do not get
tired of my problem as I am still stuck with it.

I removed the "With" and found myself back with the "The item with the
specified name wasn't found" problem.

I decided to check the Slide ID and got 259. So I changed the code to:

Sub Copy_Rectangle()
ActivePresentation.Slides.FindBySlideID(259).Shapes("Rectangle
48").Copy
ActiveWindow.Selection.SlideRange(1).Shapes.Paste
End Sub

But I still got the "The item with the specified name wasn't found"
error.

So I'm left with the thought that the "Rectangle 48" may be wrong.
"Rectangle 48" was the description generated by the macro recorder. Do
you have a code for selecting a rectangle and getting it's ID?

Regards
Richard
 
J

John Wilson

Sub getname()
On Error GoTo errhandler
Dim strName As String
Dim strSlide As String
strName = ActiveWindow.Selection.ShapeRange(1).Name
strSlide = ActiveWindow.Selection.SlideRange(1).SlideID
MsgBox "The selected shape is " & strName & vbCrLf _
& "The slide ID is " & strSlide
Exit Sub
errhandler:
MsgBox "Did you select a shape?", vbCritical
End Sub

Be careful with spaces and capitals in the shape name you use.
--
Amazing PPT Hints, Tips and Tutorials

http://www.PPTAlchemy.co.uk
http://www.technologytrish.co.uk
email john AT technologytrish.co.uk
 
W

wadiuwant

Sub getname()
On Error GoTo errhandler
Dim strName As String
Dim strSlide As String
strName = ActiveWindow.Selection.ShapeRange(1).Name
strSlide = ActiveWindow.Selection.SlideRange(1).SlideID
MsgBox "The selected shape is " & strName & vbCrLf _
 & "The slide ID is " & strSlide
 Exit Sub
errhandler:
 MsgBox "Did you select a shape?", vbCritical
End Sub

Be careful with spaces and capitals in the shape name you use.
--
Amazing PPT Hints, Tips and Tutorials

http://www.PPTAlchemy.co.ukhttp://www.technologytrish.co.uk
email john AT technologytrish.co.uk












- Show quoted text -

Thank you.

I ran getname. The selected shape is Rectangle 48. and the slide ID is
259.

So my identifiers seem to be correct.

However, I'm still stuck with the "The item with the specified name
wasn't found" error.

The debugger hilites:

ActivePresentation.Slides.FindBySlideID(259).Shapes("Rectangle
48").Copy

??????????

As an experiment I tried running my original faulty code (from the
first email) and the new code on the slide, which actually contains
Rectangle 48. No change. Still the same error with both.

Regards
Richard
 

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