Aligning a connector to a cell edge?
Dan,
Try this.
The help is somewhat misleading, as it states:
"EndX Required Single. The horizontal position (in points) of the
connector's end point relative to the upper-left corner of the document."
However, it seems that it is really relative to the start X and Y, not the
document.
You could add another argument to the function to dictate the type of
alignment required; this just assume right and left, centred.
Private Type RECT
x1 As Single
y1 As Single
x2 As Single
y2 As Single
End Type
Private Sub CommandButton1_Click()
Call AddConnectorByRanges(Range("B4"), Range("H22"))
End Sub
Public Function AddConnectorByRanges(StartRange As Range, _
EndRange As Range, _
Optional ConType As MsoConnectorType
= msoConnectorElbow) _
As Boolean
Dim Coords As RECT
With StartRange
Coords.x1 = .Left + .Width
Coords.y1 = .Top + .Height / 2
End With
With EndRange
Coords.x2 = .Left - Coords.x1
Coords.y2 = (.Top + .Height / 2) - Coords.y1
End With
With Coords
ActiveSheet.Shapes.AddConnector ConType, .x1, .y1, .x2, .y2
End With
End Function
NickHK
"Dan" wrote in message
...
I would like to use a connector (like msoConnectorElbow), but without any
shapes in the project. I want to align the connector (beginning and end
points) to corners of cells.
The connector object needs coordinates in points. Is there a way to
generate
the x,y points based on the cell that I want to align it with?
Thanks!
dan
|