Consulting

Results 1 to 6 of 6

Thread: Solved: Is the coordinate system inside a chart area different than outside.

  1. #1
    VBAX Regular
    Joined
    Apr 2011
    Posts
    15
    Location

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

    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?

  2. #2
    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.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  3. #3
    VBAX Regular
    Joined
    Apr 2011
    Posts
    15
    Location

    Code that translates Chart coordinate to drawing layer coordinates

    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

    [vba]
    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

    [/vba]

  4. #4
    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")
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  5. #5
    VBAX Regular
    Joined
    Apr 2011
    Posts
    15
    Location
    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.
    [VBA]
    dXval = ExecuteExcel14Macro("GET.CHART.ITEM(1,2""S1P3"")")
    dXval = ExecuteExcel14Macro("GET.CHART.ITEM(2,2""S1P3"")")

    [/VBA]

  6. #6
    I expect the text S1P3 must be replaced with Chart .
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •