Reputation: 19
I can't seem to return the counter value at the end of the routine.
Sub CountCheckBoxes(sldTemp As Slide)
Dim counter As Integer
Dim shpTemp As Shape
For Each shpTemp In sldTemp.Shapes
If shpTemp.Type = msoOLEControlObject Then
If TypeName(shpTemp.OLEFormat.Object) = "CheckBox" Then
If shpTemp.OLEFormat.Object.Value = True Then
counter = counter + 1
End If
End If
End If
Next
Return counter
End Function
EDIT
NEW CODE: Problem is when I type Return Counter
then hit enter. The reason I have this function is to count how many of my checkboxes on a slide are true then return the value:
Function CountCheckBoxes(sldTemp As Slide) As Integer
Dim counter As Integer
Dim shpTemp As Shape
For Each shpTemp In sldTemp.Shapes
If shpTemp.Type = msoOLEControlObject Then
If TypeName(shpTemp.OLEFormat.Object) = "CheckBox" Then
If shpTemp.OLEFormat.Object.Value = True Then
counter = counter + 1
End If
End If
End If
Next
Return counter
End Function
Upvotes: 0
Views: 310
Reputation: 415735
For fun:
Function CountCheckBoxes(sldTemp As Slide) As Integer
Return sldTemp.Shapes.Count(Function(s) s.Type = msoOLEControlObject AndAlso TypeName(s.OLEFormat.Object) = "CheckBox" AndAlso s.OLEFormat.Object.Value)
End Function
Upvotes: 2