関数・メソッド

3Dの図形を作成する【Shape.ThreeDプロパティ】【ExcelVBA】

Shape.ThreeDプロパティ

図形を立体(3D)にしたいときは Shapeオブジェクト の ThreeDプロパティ を使います。
3Dと言っても本当の3Dではなく、面を追加して立体的に見せるものです。

構文
Object.ThreeD

Object Shapeオブジェクト を表す変数。

ThreeDで使える主なプロパティ

Visible 3Dを有効/無効
Depth 奥行き
RotationX 上下の傾き
RotationY 左右の傾き
RotationZ 正面方向の回転
Perspective 遠近感
Material メタリック

 

3Dの図形を作成するサンプルコード

Public Sub Sample()
'四角柱を作る
    Dim shp As Shape
   '四角形を作成
    Set shp = ActiveSheet.Shapes.AddShape(msoShapeRectangle, 50, 50, 100, 100)

   '■3D設定
    With shp.ThreeD
        .Visible = True
        .Depth = 40         '奥行き(厚み)
        .RotationX = 20     '上下の角度
        .RotationY = 30     '左右の角度
    End With
    
End Sub

Public Sub Cylinder()
'円柱を作る
    Dim shp As Shape
   '楕円を作成
    Set shp = ActiveSheet.Shapes.AddShape(msoShapeOval, 200, 50, 100, 100)

   '■3D設定
    With shp.ThreeD
        .Visible = msoTrue
        .Depth = 60          '円柱の高さ
        .RotationX = 0
        .RotationY = -40
        .PresetMaterial = msoMaterialMetal 'メタリックにする
    End With
        
    shp.Fill.ForeColor.RGB = RGB(50, 100, 200) ' 楕円の色変更
    
End Sub

 

関連記事

コメント