In Microsoft PowerPoint, you record a macro that is to insert an object into a presentation slide, and then run the macro. When you do this, you may receive a run-time error message that resembles the following error message:
The item with the specified name wasn't found.
When you click End on the error message, the object appears as expected.
This behavior occurs with AutoShapes, with Rectangles, with Ovals, with Text Boxes, with WordArt, with ClipArt, and with Pictures.
In Microsoft Office PowerPoint 2003 and in earlier versions of PowerPoint, point to Macro on the Tools menu, and then click Macros.
In Microsoft Office PowerPoint 2007, click Macros on the Developer tab in the Code group.
In the Macro name list, click Test, and then click Edit.
In PowerPoint 2003 and in earlier versions of PowerPoint, the macro resembles the following macro.
Note The coordinates will vary.
Sub Test()
ActiveWindow.Selection.SlideRange.Shapes.AddShape(msoShapeOval, 246#, 198#, 210#, 228#).Select
ActiveWindow.Selection.Unselect
ActiveWindow.Selection.SlideRange.Shapes("Oval 4").Select
End Sub
In PowerPoint 2007, the macro resembles the following macro.
Note The coordinates will vary.
Sub Test()
ActiveWindow.Selection.SlideRange.Shapes.AddShape(msoShapeOval, 192#, 54#, 222#, 132#).Select
ActiveWindow.Selection.Unselect
ActiveWindow.Selection.SlideRange.Shapes("Oval 4").Select
ActiveWindow.View.GotoSlide Index:=ActivePresentation.Slides.Add(Index:=2, Layout:=ppLayoutText).SlideIndex
End Sub
Edit the macro so that it reads as follows.
Sub Test()
ActiveWindow.Selection.SlideRange.Shapes.AddShape(msoShapeOval, 246#, 198#, 210#, 228#).Select
'grab the name of the shape just created
strName = ActiveWindow.Selection.ShapeRange.Name
ActiveWindow.Selection.Unselect
'select that shape using the NEW name
ActiveWindow.Selection.SlideRange.Shapes(strName).Select
End Sub
In the Visual Basic Editor window, click Run Sub/UserForm on the Run menu.
In the Macros dialog box, click Test, and then click Run.
In the PowerPoint window, a shape is inserted into the slide, and you do not receive an error message.
To reproduce the problem, follow these steps, as appropriate for the version of PowerPoint that you are running.
Microsoft PowerPoint 2002 or PowerPoint 2003
Start PowerPoint.
On the Tools menu, point to Macro, and then click Record New Macro.
Type Test in the Macro name box, and then click OK.
On the Drawing toolbar, click Oval.
Draw an oval on the slide.
Click outside the oval to clear the selection of the oval.
Click to reselect the oval.
On the Tools menu, point to Macro, and then click Stop Recording.
On the Insert menu, click New Slide.
On the Tools menu, point to Macro, and then click Macros.
In the Macro name list, click Test, and then click Run.
Notice that
the oval appears as expected.
Delete the oval.
On the Tools menu, point to Macro, and then click Macros.
In the Macro name list, click Test, and then click Run.
You receive the run-time error message that is mentioned in the "Symptoms" section.
PowerPoint 2007
In PowerPoint 2007, there is no Record New Macro command to directly record macros. To reproduce the problem, follow these steps:
Start PowerPoint 2007.
On the Developer tab, click Visual Basic in the Code group to open the Visual Basic Editor.
Right-click VBAProject (Presentation1), point to Insert, and then click Module.
Add the following code in the Module1(Code) window to create a new slide and to add a shape.
Sub Test()
ActiveWindow.Selection.SlideRange.Shapes.AddShape(msoShapeOval, 192#, 54#, 222#, 132#).Select
ActiveWindow.Selection.Unselect
ActiveWindow.Selection.SlideRange.Shapes("Oval 4").Select
ActiveWindow.View.GotoSlide Index:=ActivePresentation.Slides.Add(Index:=2, Layout:=ppLayoutText).SlideIndex
End Sub
On the Run menu, click Run Sub/UserForm.
You receive the run-time error message that is mentioned in the "Symptoms" section.