Shapes.Range メソッド (Publisher)

Shapes コレクション内の 図形 のサブセットを表す ShapeRange オブジェクトを返します。

構文

範囲 (インデックス)

表現Shapes オブジェクトを表す変数です。

パラメーター

名前 必須 / オプション データ型 説明
Index 必須 バリアント型 (Variant) 範囲に含まれる個々 の図形です。 図形、図形の名前を指定する文字列または整数か文字列を格納する配列のインデックス番号を指定する整数であることができます。 Index を省略すると、Range メソッドは指定したコレクション内のすべてのオブジェクトを返します。

戻り値

ShapeRange

Index に整数または文字列の配列を指定するには、 Array 関数を使用します。 たとえば、次の命令は、名前で指定した 2 つの図形を返します。

Dim arrShapes As Variant 
Dim shpRange As ShapeRange 
 
Set arrShapes = Array("Oval 4", "Rectangle 5") 
Set shpRange = ActiveDocument.Pages(1) _ 
 .Shapes.Range(arrShapes)

次の使用例は、作業中の文書の 1 番目と 3 番目の図形に、塗りつぶしのパターンを設定します。

ActiveDocument.Pages(1).Shapes.Range(Array(1, 3)).Fill _ 
 .Patterned msoPatternHorizontalBrick

次の使用例は、最初のページの "Oval 4" および "Rectangle 5" という名前の図形に、塗りつぶしのパターンを設定します。

Dim arrShapes As Variant 
Dim shpRange As ShapeRange 
 
arrShapes = Array("Oval 4", "Rectangle 5") 
 
Set shpRange = ActiveDocument.Pages(1).Shapes.Range(arrShapes) 
 
shpRange.Fill.Patterned msoPatternHorizontalBrick

次の使用例は、最初のページのすべての図形に塗りつぶしのパターンを設定します。

ActiveDocument.Pages(1).Shapes _ 
 .Range.Fill.Patterned msoPatternHorizontalBrick

次の使用例は、最初のページの 1 番目の図形に塗りつぶしのパターンを設定します。

Dim shpRange As ShapeRange 
 
Set shpRange = ActiveDocument.Pages(1).Shapes.Range(1) 
 
shpRange.Fill.Patterned msoPatternHorizontalBrick

次の使用例は、最初のページのすべてのオートシェイプを含む配列を作成し、その配列を使って図形の範囲を定義した後、範囲内のすべての図形を左右に整列させます。

Dim numShapes As Long 
Dim numAutoShapes As Long 
Dim autoShpArray As Variant 
Dim intLoop As Integer 
Dim shpRange As ShapeRange 
 
With ActiveDocument.Pages(1).Shapes 
 
 numShapes = .Count 
 If numShapes > 1 Then 
 
 numAutoShapes = 0 
 ReDim autoShpArray(1 To numShapes) 
 
 For intLoop = 1 To numShapes 
 If .Item(intLoop).Type = msoAutoShape Then 
 numAutoShapes = numAutoShapes + 1 
 autoShpArray(numAutoShapes) = .Item(intLoop).Name 
 End If 
 Next 
 
 If numAutoShapes > 1 Then 
 ReDim Preserve autoShpArray(1 To numAutoShapes) 
 Set shpRange = .Range(autoShpArray) 
 shpRange.Distribute _ 
 DistributeCmd:=msoDistributeHorizontally, _ 
 RelativeTo:=False 
 End If 
 
 End If 
 
End With

サポートとフィードバック

Office VBA またはこの説明書に関するご質問やフィードバックがありますか? サポートの受け方およびフィードバックをお寄せいただく方法のガイダンスについては、Office VBA のサポートおよびフィードバックを参照してください。