返回 ShapeRange 对象,该对象代表一个 Shapes 集合中的形状子集。
expression.Range(Index)
expression 必选。该表达式返回一个 Shapes 集合对象。
Index 可选。Variant 类型。要包含在范围内的单个形状。可以是 Integer 类型值(指定形状的索引号)、String 类型值(指定形状的名称)或者数组(包括整数或字符串)。如果忽略此参数,则 Range 方法返回指定集合中的所有对象。
返回一个 ShapeRange 对象。
expression.Range(Index)
expression 必选。该表达式返回上述对象之一。
Index 必选。Variant 类型。要包含在范围内的单个形状。可以是 Integer 类型值(指定形状的索引号)、String 类型值(指定形状的名称)或者数组(包括整数或字符串)。如果忽略此参数,则 Range 方法返回指定集合中的所有对象。
返回 SlideRange 对象,该对象代表一个 Slides 集合中的幻灯片子集。
expression.Range(Index)
expression 必选。该表达式返回一个 Slides 集合对象。
Index 可选。Variant 类型。要包含在范围内的单张幻灯片。可以是 Integer 类型值(指定形状的索引号)、String 类型值(指定形状的名称)或者数组(包括整数或字符串)。如果忽略此参数,则 Range 方法返回指定集合中的所有对象。
虽然用 Range 方法可以返回任意数量的形状或幻灯片,但是如果只想返回集合中的单个成员,则使用 Item 方法更简单。例如,Shapes(1)
比 Shapes.Range(1)
简单,Slides(2)
比 Slides.Range(2)
简单。
若要为 Index 指定一个整数或字符串数组,可以使用 Array 函数。例如,以下指令返回用名称指定的两个形状。
Dim myArray() As Variant, myRange As Object
myArray = Array("Oval 4", "Rectangle 5")
Set myRange = ActivePresentation.Slides(1).Shapes.Range(myArray)
本示例设置 myDocument
中第一个形状和第三个形状的填充图案。
Set myDocument = ActivePresentation.Slides(1)
myDocument.Shapes.Range(Array(1, 3)).Fill _
.Patterned msoPatternHorizontalBrick
本示例设置第一张幻灯片中形状 Oval 4 和 Rectangle 5 的填充图案。
Dim myArray() As Variant, myRange As Object
myArray = Array("Oval 4", "Rectangle 5")
Set myRange = ActivePresentation.Slides(1).Shapes.Range(myArray)
myRange.Fill.Patterned msoPatternHorizontalBrick
本示例设置第一张幻灯片中所有形状的填充图案。
ActivePresentation.Slides(1).Shapes.Range.Fill _
.Patterned Pattern:=msoPatternHorizontalBrick
本示例设置第一张幻灯片中第一个形状的填充图案。
Set myDocument = ActivePresentation.Slides(1)
Set myRange = myDocument.Shapes.Range(1)
myRange.Fill.Patterned msoPatternHorizontalBrick
本示例创建一个包含第一张幻灯片中所有自选图形的数组,并用它定义一个形状范围,然后在该范围内水平地分布所有这些形状。
With myDocument.Shapes
numShapes = .Count
'Continues if there are shapes on the slide
If numShapes > 1 Then
numAutoShapes = 0
ReDim autoShpArray(1 To numShapes)
For i = 1 To numShapes
'Counts the number of AutoShapes on the Slide
If .Item(i).Type = msoAutoShape Then
numAutoShapes = numAutoShapes + 1
autoShpArray(numAutoShapes) = .Item(i).Name
End If
Next
'Adds AutoShapes to ShapeRange
If numAutoShapes > 1 Then
ReDim Preserve autoShpArray(1 To numAutoShapes)
Set asRange = .Range(autoShpArray)
asRange.Distribute msoDistributeHorizontally, False
End If
End If
End With
本示例设置第一张幻灯片和第三张幻灯片的标题颜色。
Set mySlides = ActivePresentation.Slides.Range(Array(1, 3))
mySlides.ColorScheme.Colors(ppTitle).RGB = RGB(0, 255, 0)
本示例设置幻灯片“Slide6”和幻灯片“Slide8”的标题颜色。
Set mySlides = ActivePresentation.Slides _
.Range(Array("Slide6", "Slide8"))
mySlides.ColorScheme.Colors(ppTitle).RGB = RGB(0, 255, 0)
本示例设置当前演示文稿中所有幻灯片的标题颜色。
Set mySlides = ActivePresentation.Slides.Range
mySlides.ColorScheme.Colors(ppTitle).RGB = RGB(255, 0, 0)
本示例创建一个包含当前演示文稿中所有标题幻灯片的数组,并用它定义一个幻灯片范围,然后设置该范围内所有幻灯片的标题颜色。
Dim MyTitleArray() As Long
Set pSlides = ActivePresentation.Slides
ReDim MyTitleArray(1 To pSlides.Count)
For Each pSlide In pSlides
If pSlide.Layout = ppLayoutTitle Then
nCounter = nCounter + 1
MyTitleArray(nCounter) = pSlide.SlideIndex
End If
Next pSlide
ReDim Preserve MyTitleArray(1 To nCounter)
Set rngTitleSlides = ActivePresentation.Slides.Range(MyTitleArray)
rngTitleSlides.ColorScheme.Colors(ppTitle).RGB = RGB(255, 123, 99)