0

My macro throws an "index out of range" error as it goes through ActiveWindow.Selection.shapeRange on one particular group of shapes only.

The specific presentation can be found at http://free-editable-worldmap-for-powerpoint.en.softonic.com (select any larger group of shapes, i.e. South America, and run the code to replicate error)

The code is below:

Dim shp As Shape
For Each shp In ActiveWindow.Selection.shapeRange
    shp.Fill.Transparency = 0 'Or any other code
Next shp

I also tried using For loop with no success ('For i=1 To ActiveWindow.Selection.shapeRange.Count Step 1'). Notably, there is no particular index at which the error is thrown- sometimes it's i=3, sometimes i=35, sometimes more.

4

1 回答 1

0

这张幻灯片中有一些msoLine形状 ( shp.Type = 9)。这将引发错误:

指定的值超出范围。

如果您无意中选择了它们。(我预计会出现Object does not support this property or method错误,因为 msoLine 没有.Fill成员 - 但有时错误消息是神秘的。无论如何,可以捕获此错误)。

该幻灯片上的所有其他形状都是类型 5 或 6,它们支持.Fill.

我用它来调试,虽然我无法复制你的具体错误(除非你只是错误地输入了错误描述),也许它会对你有所帮助。它尝试为幻灯片中Fill.Forecolor所有形状设置 ,并将一些有关错误的信息打印到 VBE 中的即时窗口。

Sub Test()
'Determine there are shapes which do not have a .Fill.ForeColor
Dim shp As Shape
For Each shp In ActivePresentation.Slides(1).Shapes
    On Error Resume Next
    shp.Fill.ForeColor.RGB = 43506
    If Err.Number <> 0 Then
        Debug.Print Err.Description & " >> " & _
            shp.Name & " is shape type " & shp.Type
        On Error GoTo 0
    Else:
        shp.Fill.Transparency = 0
        shp.Fill.ForeColor.RGB = 12632256
    End If
Next

End Sub
于 2013-08-29T16:18:24.977 回答