I have an excel chart (Stock candlestick chart) which I created manually.
I draw lines on the chart (say a horizontal line from (x1=1 to x2=4 along y = 27)
You can see the red horizontal line in the screen shot below
Candle.png
Though for a quick screenshot purpose, I have shown a column chart above, I actually want to do it on a stock-candlestick chart.
I am comfortable with writing excel functions which do other stuff. I am also able to call these functions from a cell =MyFunction(10,20). But unable to figure out how to do this for a sub/function/macro which draws a line on the chart.
From the docs, it seems I need a sub/function which does something like this
Sub DrawLine()
ActiveSheets.ChartObjects(1).Shapes.AddLine(1, 27, 4, 27)
End Sub
But I have a few problems
1) I want to the co-ordinates of the lines to be points on the chart (x & y co-ordinates as per the chart axis) - however AddLine seems to be absolute geometric points on the chart rather than points which can be represented by x,y co-ordinates as per the chart axes.
2) I am unable to figure how to call this DrawLine so as to draw the line. If I call it from the Run Menu of the VBAProject, I get a
Run Time error 24 - object required.
So how do I call this? In the future, I will also pass parameters to the sub so as to draw multiple unconnected lines which don't pass through or connect the candle itself. How do I do this? I am experienced programmer but only have a basic experience with MS Office programming.
Bookmarks