Attaching a Textbox to a point or line on a chart in Excel/VBA -
i wondering how attach textbox point or line in excel chart macro working on. have been using .addtextbox
method such
.shapes.addtextbox(msotextorientationhorizontal, 150, 250, 100, 15) _ .textframe.characters.text = "temperature"
but have manually drag textbox on line on chart representing orientation of chart not line. there way convert line/point chart orientation use variable? or way? possibly using datalabel function, though want able customize 1 of axis locations. thanks
to solve question need left & top position of 2 objects:
- chart itself, position set in relation top-left corner of sheet range area
- point in series position set in relation top-left corner of chart
combination of both result following code (fixed parameters-required changes situation, more dynamic loop)
sub add_text_to_point() dim tmpchr chartobject set tmpchr = sheet1.chartobjects(1) 'put index of chartobject here 'for first serie, point 2nd here '(change accordingly need) tmpchr.chart.seriescollection(1).points(2) sheet1.shapes.addtextbox(msotextorientationhorizontal, _ .left + tmpchr.left, _ .top + tmpchr.top, _ 100, 15) _ .textframe.characters.text = "temperature" end end sub
after result presenting picture below.
Comments
Post a Comment