1

Excel のフリーフォーム ツール (「フリーフォーム: シェイプ」または「フリーフォーム: スクリブル」) を使用して、開いた輪郭または閉じた輪郭を持つシェイプを作成することができます。「Open」または「Closed」、それらの Type は「msoFreefrom」であり、値を読み取ってそれらを区別するプロパティが見つかりませんでした。

Excelは何とかそれらを区別します。図形の 1 つをクリックすると、[書式] タブが表示され、その内容が図形の輪郭に応じて変化します。(線のような開いた輪郭形状、正方形のような閉じた輪郭形状)。

vbaでそれらを区別したい。vbaでエラーを発生させることでこれを管理します。輪郭の形状が近い場合、線の矢印を設定しようとするとエラーがスローされます。(以下のコードを参照してください) より良い方法はありますか?

Sub Try01()
ActiveWindow.DisplayGridlines = False
Dim ws As Worksheet
Set ws = ActiveSheet
Dim ds As Shape
For Each ds In ws.Shapes
    ds.Delete
Next ds
Dim myShape As Shape, myShape2 As Shape
' Open contour shape
With ws.Shapes.BuildFreeform(msoEditingAuto, 100, 100)
    .AddNodes msoSegmentLine, msoEditingAuto, 200, 100
    .AddNodes msoSegmentLine, msoEditingAuto, 200, 200
    .AddNodes msoSegmentLine, msoEditingAuto, 100, 200
    '.AddNodes msoSegmentLine, msoEditingAuto, 100, 100
    Set myShape = .ConvertToShape
End With
myShape.Name = "MyL"
'Closed contoru shape
With ws.Shapes.BuildFreeform(msoEditingAuto, 300, 100)
    .AddNodes msoSegmentLine, msoEditingAuto, 400, 100
    .AddNodes msoSegmentLine, msoEditingAuto, 400, 200
    .AddNodes msoSegmentLine, msoEditingAuto, 300, 200
    .AddNodes msoSegmentLine, msoEditingAuto, 300, 100
    Set myShape2 = .ConvertToShape
End With
myShape2.Name = "MyS"
'You can set styles no error
myShape.ShapeStyle = myShape2.ShapeStyle

Debug.Print myShape.Line.BeginArrowheadStyle
'Open contour you can change line arrow type
myShape.Line.BeginArrowheadStyle = msoArrowheadDiamond

Debug.Print myShape2.Line.BeginArrowheadStyle
'But for closed contour you can not
myShape2.Line.BeginArrowheadStyle = msoArrowheadDiamond
End Sub

ご協力ありがとうございました :)

4

0 に答える 0