msblane
asked on
Item name not found in shapes collection
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( "ProspectT ext")
Set oCallout = ActivePresentation.Slides( 2).Shapes( "ProspectC allout")
oCheck = ActivePresentation.Slides( 2).Shapes( "ProspectC heck")
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!
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(
Set oCallout = ActivePresentation.Slides(
oCheck = ActivePresentation.Slides(
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!
ASKER
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!
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!
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
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(
strReport = strReport + oshp.Name & vbCrLf
Next oshp
MsgBox strReport
End Sub
ASKER
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.Sli deRange
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.Sha peRange.Na me _
& Chr$(13) & "The slide is named " & ActiveWindow.Selection.Sli deRange.Na me
Exit Sub
errhandler:
MsgBox "There's an error, maybe you've selected more that one shape?"
End Sub
Now I am very confused! What am I missing?
Public Sub RenameShapes()
Dim s As Integer, NewName As String
With ActiveWindow.Selection.Sli
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.Sha
& Chr$(13) & "The slide is named " & ActiveWindow.Selection.Sli
Exit Sub
errhandler:
MsgBox "There's an error, maybe you've selected more that one shape?"
End Sub
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.c o.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
If you want to send me a couple of slides I can take a look johnATSIGNHEREpptalchemy.c
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
ASKER
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
Thanks so much for your help!
MSB
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This line will return a Shape and since oCheck is declared as Boolean it is bound to error.
oCheck = ActivePresentation.Slides(
If it is an ActivX checkBox you need to say:
oCheck = ActivePresentation.Slides(
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