PDA

View Full Version : Solved: Is the coordinate system inside a chart area different than outside.



bigt95nt
05-01-2011, 05:14 PM
When attempting to replace the legend of a chart with a custom legend, I save the Left & Top values of the default legend and assign thoes values to the custom. How ever the new legen apears compleetly outside of the Chart. Are these coordinate systems Different?

Jan Karel Pieterse
05-02-2011, 04:10 AM
I wouldn't be surprised, but my first guess would be that you are not actually placing the textbox in the chart but rather on top of the sheet itself. Hard to say without the relevant piece of your code.

bigt95nt
05-03-2011, 01:28 AM
Below is code lifted from a book Proffessional Excel development. Any time the code is run the compiler throws an error "invalid use of .me key word" Plese comment


Sub cmdMoveArrow_Click()
Dim rngActive As Range
Dim dXval As Double
Dim dYval As Double
Dim chtChart As Chart
Set rngActive = ActiveCell
'Chart Must be Active
Me.ChartObjects(1).Activate
dXval = ExecuteExcel14Macro("GET.CHART.ITEM(1,2""S1P3"")")
dXval = ExecuteExcel14Macro("GET.CHART.ITEM(2,2""S1P3"")")
Set chtChart = Me.ChartObjects(1).Chart
With chtChart
'Convert XLM Coordinates to Drawing Object Coordinates
'The x values ae the same, but the Y values need to be fliped

dYval = .ChartArea.Height - dYval
'Move and Size the Arrow
.Shapes("linArrow").Left = .PlotArea.InsideLeft
.Shapes("linArrow").Top = .PlotArea.InsideLeft
.Shapes("linArrow").Width = dXval - .Shapes("linArrow").Left
.Shapes("linArrow").Height = dYval - .Shapes("linArrow").Top

End With
rngActive.Activate
End Sub

Jan Karel Pieterse
05-03-2011, 02:39 AM
You either have to move the code to the codemodule belonging to the worksheet where the chart object is located, or replace Me with:
Worksheets("TheSheetName")

bigt95nt
05-03-2011, 06:16 AM
My understanding of the calls below to "GET.CHART.ITEM" is a hold over from XLM a fore-runner to VBA. The compiler is flagging these two statemens as syntax errors. Is there some type of "include" file or sometime refrence to a library that defines these calls.

dXval = ExecuteExcel14Macro("GET.CHART.ITEM(1,2""S1P3"")")
dXval = ExecuteExcel14Macro("GET.CHART.ITEM(2,2""S1P3"")")

Jan Karel Pieterse
05-03-2011, 07:09 AM
I expect the text S1P3 must be replaced with Chart .