Excel VBA: How to obtain a reference to a Shape from the ChartObject
I am trying to obtain a reference to a Shape in a Worksheet, corresponding
to a ChartObject. I found no certain way of doing this. The only
approximation, by trial-and-error and simply tested in a few cases, is
assuming that the ZOrder of a ChartObject is the same as the
ZOrderPosition of the corresponding Shape:
Function chobj2shape(ByRef cho As ChartObject) As Shape
' It appears that the ZOrder of a ChartObject is the same as the
ZOrderPosition of the corresponding Shape
Dim zo As Long
Dim ws As Worksheet
Dim shc As Shapes
Dim sh As Shape
zo = cho.ZOrder
Set ws = cho.Parent
Set shc = ws.Shapes
Set sh = shc.Item(zo)
Set chobj2shape = sh
'Set sh = Nothing
End Function
(a slight excess of defined variables is used for debugging purposes).
Is there any more certain way of doing this?
No comments:
Post a Comment