Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Item name not found in shapes collection

Posted on 2013-06-12
7
2,788 Views
Last Modified: 2013-06-18
Hi,

I am an experienced VBA programmer but have only just begun using VBA in Powerpoint 2010.  I am trying to set write code to a) set two shape object variables to particular shapes on the slide, b) check the value of a checkbox and c) to show or hide the two shapes depending on the value of the checkbox.

I have named the two shapes "ProspectText" and "ProspectCallout" and the checkbox (ProspectCheck).

My initial code (below) to set the shape objects is generating an error that says something like "Item "ProspectText" not found in shapes collection."

Dim oText As Shape
Dim oCallout As Shape
Dim oCheck As Boolean
    Set oText = ActivePresentation.Slides(2).Shapes("ProspectText")
    Set oCallout = ActivePresentation.Slides(2).Shapes("ProspectCallout")
    oCheck = ActivePresentation.Slides(2).Shapes("ProspectCheck")
    If oCheck = True Then
        ShowShapes oText, oCallout
    Else
        HideShapes oText, oCallout
    End If
End Sub

I have checked in the Selection and Visibility pane and through code to ensure the names are correct.

Does anyone have any ideas on what to try?

Thanks!
0
Comment
Question by:msblane
  • 4
  • 3
7 Comments
 
LVL 23

Expert Comment

by:JSRWilson
ID: 39240769
Are these PowerPoint shapes or Items from the Control Toolbox? Probably worth posting a simple example AND what you want to acheive because non native activx shapes need to be referenced differently.

This line will return a Shape and since oCheck is declared as Boolean it is bound to error.
oCheck = ActivePresentation.Slides(2).Shapes("ProspectCheck")

If it is an ActivX checkBox you need to say:

oCheck = ActivePresentation.Slides(2).Shapes("ProspectCheck").OLEFormat.Object.Value

Almost certainly you would want to put the checkbox routine into the checkbox Change event.

Private Sub ProspectCheck_Click()
If Me.ProspectCheck.Value = True Then

Else

End If
End Sub
0
 

Author Comment

by:msblane
ID: 39251408
Hi,

The two shapes are PowerPoint shapes (one is a callout, the other a text box).  The checkbox is a form control (but not an activex).  I understand what you are saying about putting it on the checkbox change event and will do that.  However, the problem with the code still remains - it will not recognize the named shapes as shapes.

Thanks for your help!
0
 
LVL 23

Expert Comment

by:JSRWilson
ID: 39251418
And you are sure the shapes are on Slide 2?

If you run this does it return the correct shape names.

Sub chexNames()
Dim strReport As String
Dim oshp As Shape
For Each oshp In ActivePresentation.Slides(2).Shapes
strReport = strReport + oshp.Name & vbCrLf
Next oshp
MsgBox strReport
End Sub
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 

Author Comment

by:msblane
ID: 39255549
I have run various pieces of code (see the most recent below) to check the names, and they all found it, but your code does not.  In fact the names in the Selection and Visibility pane are quite different from those listed in strReport.

Now I am very confused!  What am I missing?

Public Sub RenameShapes()
Dim s As Integer, NewName As String

With ActiveWindow.Selection.SlideRange
    For s = 1 To .Shapes.Count
        .Shapes(s).Select ' So you can see the object in question
        NewName = InputBox(.Shapes(s).Name) ' Tell what current name it is and ask for new name
        If Len(NewName) > 0 Then .Shapes(s).Name = NewName ' If you typed a new name, apply it
    Next s ' 1 To .Shapes.Count
End With
End Sub

Sub identifyme()
On Error GoTo errhandler
MsgBox "The shape is named " & ActiveWindow.Selection.ShapeRange.Name _
& Chr$(13) & "The slide is named " & ActiveWindow.Selection.SlideRange.Name
Exit Sub
errhandler:
MsgBox "There's an error, maybe you've selected more that one shape?"
End Sub
0
 
LVL 23

Expert Comment

by:JSRWilson
ID: 39255832
My code should return the correct names. Are you SURE the shapes are on Slide 2. (That's the second slide not a name you recovered from code.)

If you want to send me a couple of slides I can take a look johnATSIGNHEREpptalchemy.co.uk

Add a note to remind me what it's about.

You probably know this but you don't need code to name shapes. Just select the name in the selection pane and type.

John
0
 

Author Comment

by:msblane
ID: 39255866
You have hit the nail on the head.  When I began this exercise, it was slide 2.  Now it's slide 1.  Sorry to waste your time!  Can you tell me how I rename the slides so that I can refer to them more stably?

Thanks so much for your help!

MSB
0
 
LVL 23

Accepted Solution

by:
JSRWilson earned 500 total points
ID: 39255950
You can name the slides in code

Sub name_Slide()
Dim strName As String
strName = InputBox("Name?")
ActiveWindow.Selection.SlideRange(1).Name = strName
End Sub

Sub chex()
MsgBox ActivePresentation.Slides("myName").Shapes(1).Name
End Sub

I would use the SlideID though this doesn't change in normal use. You need to read the ID first though (just once)


Sub getID()
MsgBox ActiveWindow.Selection.SlideRange(1).SlideID
End Sub
Sub getslideByID()
Dim osld As Slide
Set osld = ActivePresentation.Slides.FindBySlideID(257)' put in the correct ID
MsgBox osld.Shapes(1).Name 'now use osld to refer to the slide
End Sub
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The System Center Operations Manager 2012, known as SCOM, is a part of the Microsoft system center product that provides the user with infrastructure monitoring and application performance monitoring. SCOM monitors:   Windows or UNIX/LinuxNetwo…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question