none
GetChartElement on multiple screens with different zoom factor RRS feed

  • Question

  • The chart method GetChartElement in Excel vba works fine as long as the same zoom factor is used on all screens. If the Windows zoom factor is different, the zoom factor of windows 1 is used by GetChartElement for all windows.

    Example: Screen 1: Zoom factor 200%; Screen 2: Zoom factor 100%
    Excel window is on screen 2.

    The mouse is 100 from the top and 75 from the left border of the graph. GetChartElement delivers information about the object that is 200 from the top and 150 from the left border. Thus, the mouse position cannot be used to retrieve information about chart elements.

    If the excel window is moved to screen 1, anything works fine.

    This can be tested with the simple code from https://docs.microsoft.com/en-us/office/vba/api/excel.chart.getchartelement

    Private Sub Chart_MouseMove(ByVal Button As Long, _
    ByVal Shift As Long, ByVal X As Long, ByVal Y As Long)
    Dim IDNum As Long
    Dim a As Long
    Dim b As Long

    ActiveChart.GetChartElement X, Y, IDNum, a, b
    If IDNum = xlLegendEntry Then _
    MsgBox
    "WARNING: Move away from the legend"
    End Sub

    Is there a workaround by using other methods or any other hint?

    Best regards,

    Reinhard

     

    Monday, October 21, 2019 9:05 AM