HOME > 即効テクニック > Excel VBA > 図形操作関連のテクニック > Shapeを立体表示するには−ThreeDFormat

即効テクニック

図形操作関連のテクニック

Shapeを立体表示するには−ThreeDFormat

(Excel 97/2000)
Shapeに3D効果を与えるにはThreeDプロパティーを使用してThreeDFormatオブジェクトを取得し、各種プロパティーの設定などを行います。

以下のサンプルでは四角形にテキストを追加し、塗りつぶしを行った上で左上方向への3D効果を与えた青色のShapeを作成します。

Sub CreateShapeWith3DEffect()

Dim Rng As Range
Dim Sh As Shape
Dim L As Double, T As Double, W As Double, H As Double

'指定セル範囲にあわせてShapeの位置決め
Set Rng = ActiveSheet.Range("B5:G10")
L = Rng.Left: T = Rng.Top: W = Rng.Width: H = Rng.Height
'Shapeの追加
Set Sh = Sheet1.Shapes.AddShape(msoShapeRectangle, _
    L, T, W, H)
With Sh
.Fill.ForeColor.RGB = vbBlue '塗りつぶし
.TextFrame.Characters.Text = "3DのShape" 'テキストの追加
.TextFrame.Characters.Font.Size = 32 'フォントサイズ
.TextFrame.Characters.Font.Color = vbWhite 'フォント色
.TextFrame.HorizontalAlignment = xlHAlignCenter '水平方向の位置
.TextFrame.VerticalAlignment = xlVAlignCenter '垂直方向の位置
End With

With Sh.ThreeD 'ThreeDFormatオブジェクトの取得
.Depth = 50 ' 奥行きの設定
.SetExtrusionDirection msoExtrusionTopLeft '奥行きの方向の設定
.ExtrusionColor.RGB = vbBlue '3Dの色を設定
.Visible = True
End With

End Sub

※自動書式設定にはSetThreeDFormatメソッドを用います。
※光源の位置の設定にはPresetLightingDirectionプロパティー、光の強さにはPresetLightingSoftnessプロパティーを使用します。