我似乎无法在例程结束时返回计数器值。
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
编辑
新代码:问题是当我键入Return Counter
然后按Enter键。我具有此功能的原因是计算一张幻灯片上有多少个复选框为true,然后返回值:
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
答案 0 :(得分:2)
为了娱乐:
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