ExcelのVBAについて質問です。 クラフのマーカーの値を取得したいのですが、マーカーの上をクリックしてください! となり、取得できません。 当然、マーカーは取得しています。 ElementID は2 、21 、8とか出てきます。 どの点を修正すればいいでしょうか? ちなみにこのブラフはVBAで作成しています。手動なら、作動します。 VBAで作成したグラフではできないのでしょうか? お手数ですが、ご教示をお願いします。 Sub ShowClickedChartPoint() Dim ElementID As Long Dim Arg1 As Long Dim Arg2 As Long Dim clickedChart As Chart Dim ser As Series Dim clickedDate As String Dim clickedValue As Double ' **アクティブなグラフを取得** On Error Resume Next Set clickedChart = ActiveChart On Error GoTo 0 ' **グラフが選択されていなければエラー** If clickedChart Is Nothing Then MsgBox "? グラフを選択してからクリックしてください!", vbExclamation, "エラー" Exit Sub End If ' **クリックされた要素を取得** clickedChart.GetChartElement ActiveWindow.PointsToScreenPixelsX(0), _ ActiveWindow.PointsToScreenPixelsY(0), _ ElementID, Arg1, Arg2 ' **デバッグ用(取得した ElementID, Arg1, Arg2 を表示)** MsgBox "ElementID: " & ElementID & vbCrLf & _ "Arg1 (Series): " & Arg1 & vbCrLf & _ "Arg2 (Point): " & Arg2, vbInformation, "デバッグ情報" ' **データポイントがクリックされた場合のみ処理** If (ElementID = 2 Or ElementID = 21) And Arg2 > 0 Then Set ser = clickedChart.SeriesCollection(Arg1) ' **X軸(B列: 日付)と Y軸(時間)の値を取得** clickedDate = ser.XValues(Arg2) clickedValue = ser.Values(Arg2) ' **メッセージボックスで表示** MsgBox "?? 日付: " & clickedDate & vbCrLf & _ "? 調教タイム: " & clickedValue & " 秒", _ vbInformation, "選択したデータ" Else MsgBox "マーカーの上をクリックしてください!", vbExclamation, "エラー" End If End Sub
Visual Basic