Share via

Chart.GetChartElement Method extended desktop

Anonymous
2013-09-10T20:39:38+00:00

Hi, I am getting incorrect readings from the above method when I have an extended desktop. I have screen one on my laptop and screen 2 above it on a monitor.  when I move my cursor over the graph in the monitor I get totally incorrect events, but when I moved the active window to my laptop screen it seems OK. 

The chart I'm working on is a combo chart with lines and areas (not stacked).

Is there a way to correct this?

Thanks!

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

7 answers

Sort by: Most helpful
  1. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2013-09-30T07:59:09+00:00

    Thanks for the update, that is a known issue, unfortunately there is no solution.

    Andreas.

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2013-09-26T14:53:08+00:00

    Just an update on this: if I have two windows open, regardless of which monitor they are on, the problem described above occurs if the windows have different zoom settings (within excel).

    If I have the same sheet open on two different windows and I set the zoom to the same, then the GetChartElement method works properly on both.

    If I have different zoom settings, then it works ok in one, but not the other.

    It seems like the transformation between pixels and points is affected by the window zoom setting.

    Was this answer helpful?

    0 comments No comments
  3. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2013-09-12T15:04:42+00:00

    Just an idea:

    What happens when you change the monitor settings in the Control Panel?

    Setup the monitors side by side, rather than one above the other.

    Ask you question also in the developers forum:

    social.msdn.microsoft.com/Forums/en-us/home?forum=exceldev

    Andreas.

    Was this answer helpful?

    0 comments No comments
  4. Anonymous
    2013-09-12T13:27:06+00:00

    Yep. That's the method I used, except I used a class module. 

    My code works fine but occasionally it gets into a mode where the Elements returned are very different from what's actually under the cursor.

    First time it happened it came good when I moved the window from the monitor to the laptop display.

    Today it happened again but it persisted when I tried the above work-around.

    This time I checked more closely and I verified that the elements detected were about an inch below the cursor.

    For example it was reading legend elements when the cursor was well above the legend.

    I'm wondering if others had the same problem and if so, how to protect against it.

    Was this answer helpful?

    0 comments No comments
  5. Andreas Killer 144.1K Reputation points Volunteer Moderator
    2013-09-12T10:08:24+00:00

    I can't answer your question, because I did not have Excel 2013... but maybe I can help anyway.

    In Excel 2010 it works with multiple monitors. Make a new file, copy the code below into the code module of a sheet, exit the VBA editor, switch to an other sheet an back, then hover the mouse over the chart.

    Does it work in Excel 2013? If so, show us your code.

    Andreas.

    Option Explicit

    Dim WithEvents C As Chart

    Private Sub Worksheet_Activate()

      If Me.ChartObjects.Count = 0 Then

        With WorksheetFunction

          Range("A1:A4") = .Transpose(Array("Line", 1, 2, 3))

          Range("B1:B4") = .Transpose(Array("Area", 4, 5, 6))

        End With

        ActiveSheet.Shapes.AddChart.Select

        ActiveChart.ChartType = xlLine

        ActiveChart.SetSourceData Source:=Range("A1:B4")

        ActiveChart.SeriesCollection(2).ChartType = xlArea

      End If

      Set C = Me.ChartObjects(1).Chart

    End Sub

    Private Sub C_MouseMove(ByVal Button As Long, ByVal Shift As Long, ByVal X As Long, _

        ByVal Y As Long)

      Dim ElementIDs

      Dim ElementID As Long, Arg1 As Long, Arg2 As Long

      C.GetChartElement X, Y, ElementID, Arg1, Arg2

      ElementIDs = Array("xlDataLabel", "unknown", "xlChartArea", "xlSeries", _

        "xlChartTitle", "xlWalls", "xlCorners", "xlDataTable", "xlTrendline", "xlErrorBars", _

        "xlXErrorBars", "xlYErrorBars", "xlLegendEntry", "xlLegendKey", "xlShape", _

        "xlMajorGridlines", "xlMinorGridlines", "xlAxisTitle", "xlUpBars", "xlPlotArea", _

        "xlDownBars", "xlAxis", "xlSeriesLines", "xlFloor", "xlLegend", "xlHiLoLines", _

        "xlDropLines", "xlRadarAxisLabels", "xlNothing", "xlLeaderLines", "xlDisplayUnitLabel", _

        "xlPivotChartFieldButton", "xlPivotChartDropZone")

      If ElementID <= UBound(ElementIDs) Then

        Range("D1") = ElementIDs(ElementID)

      Else

        Range("D1") = "Unknown " & ElementID

      End If

      Range("D2") = Arg1

      Range("D3") = Arg2

      DoEvents

    End Sub

    Was this answer helpful?

    0 comments No comments