如何确定线图对象的终点?

我在Excel电子表格上有一行(= autoshape)绘图对象。 我想确定它“指向”哪个单元格。 为此,我需要知道起点和终点的坐标。

我可以使用.Top.Height.Width.Height来确定边界矩形,但是该线可能位于该矩形的两个不同位置。

要做到这一点,你必须使用成员HorizontalFlipVerticalFlip 。 下面的函数应该做你想要的:

 Function CellFromArrow(ByVal s As Shape) As Range Dim hFlip As Integer Dim vFlip As Integer hFlip = s.HorizontalFlip vFlip = s.VerticalFlip Select Case CStr(hFlip) & CStr(vFlip) Case "00" Set CellFromArrow = s.BottomRightCell Case "0-1" Set CellFromArrow = Cells(s.TopLeftCell.Row, s.BottomRightCell.Column) Case "-10" Set CellFromArrow = Cells(s.BottomRightCell.Row, s.TopLeftCell.Column) Case "-1-1" Set CellFromArrow = s.TopLeftCell End Select End Function 

此代码在Excel 2010中进行了testing。似乎正常工作。 希望这可以帮助!

编辑:如果你不得不担心组中包含的形状,那么似乎唯一的解决scheme是取消组合,迭代通过形状,然后重新组合。 像下面这样:

 Dim s As Shape For Each s In ActiveSheet.Shapes If s.Type = msoGroup Then Dim oldName as String Dim sGroup As GroupShapes Dim GroupMember as Shape Set sGroup = s.GroupItems oldName = s.Name 'To preserve the group Name s.Ungroup For Each GroupMember in sGroup 'DO STUFF Next Set s = sGroup.Range(1).Regroup 'We only need to select one shape s.Name = oldName 'Rename it to what it used to be End If Next 

您可以参考ShapeRange文档以获取有关重组方法的更多信息。

让我知道这是否适合你!