0

msoLine形状オブジェクトの始点と終点の座標にアクセスする方法はありますか? 私はExcel 2010でレガシーファイルを扱っています(Excel 2003からだと思います)。

オブジェクトmsoFreeformを指定すると、次のようなものを使用して、さまざまな座標に順番にアクセスできます。

  With myDocument.Shapes(i)
     If .Type = msoFreeform Then
       nodeCount = .Nodes.Count
       For k = 1 To nodeCount
         pointsArray = .Nodes.Item(k).Points
         X1 = pointsArray(1, 1)
         Y1 = pointsArray(1, 2)
       Next k
     End If
  End With

ただし、このメソッドは、始点と終点を返しても、何も返さないmsoLineオブジェクトに対しては失敗します。.Nodes.Item(k).Points.Nodes.Count2

何か不足していますか?

4

2 に答える 2

1

これは機能します:

'The "flips" helps to work out which pair of corners of an imaginary rectangle surrounding the line represents the correct diagonal.

サブ testLineCoords()

Dim bHflip As Boolean
Dim bVflip As Boolean
Dim nBegin As Long
Dim nEnd As Long
Dim oShape As Shape
Dim aC(1 To 4, 1 To 2) As Double

Set oShape = ShTmp.Shapes("MyLine")
With oShape
    aC(1, 1) = .Left:           aC(1, 2) = .Top
    aC(2, 1) = .Left + .Width:  aC(2, 2) = .Top
    aC(3, 1) = .Left:           aC(3, 2) = .Top + .Height
    aC(4, 1) = .Left + .Width:  aC(4, 2) = .Top + .Height

    bHflip = .HorizontalFlip
    bVflip = .VerticalFlip
End With

If bHflip = bVflip Then
    If bVflip = False Then
        ' down to right
        nBegin = 1: nEnd = 4
    Else
        ' up to left
        nBegin = 4: nEnd = 1
    End If
ElseIf bHflip = False Then
    ' up to right
    nBegin = 3: nEnd = 2
Else
    ' down to left
    nBegin = 2: nEnd = 3
End If

Debug.Print "---------------------------------"
Debug.Print "Begin X:Y"
Debug.Print aC(nBegin, 1); aC(nBegin, 2)
Debug.Print "End X:Y"
Debug.Print aC(nEnd, 1); aC(nEnd, 2)

サブ終了

残念ながら、私はそれを信用することはできません: 元の解決策

よろしく、 エミエル

于 2013-05-13T11:11:36.930 に答える
0

X/Y の開始点と終了点を取得する場合msoLineは、次の手順を実行します。

Dim myMsoLine As Shape
Set myMsoLine = ActiveSheet.Shapes(3)
Dim X1, X2, Y1, Y2
'points of msoLine

With myMsoLine
    X1 = .Left
    Y1 = .Top
    X2 = .Width + .Left
    Y2 = .Height + .Top
End With

Debug.Print X1, Y1, X2, Y2

msoLine通常、この状況では形状に節点はありません。(Excel 2010 でテスト済み)

于 2013-03-19T11:16:26.447 に答える