分享

类 "Chart类"

 VB资料馆 2023-01-16 发布于河北

类 "Chart类" 中写以下代码,其实,有第一句就够了,其它的都是它的事件进行的事项
Public WithEvents Chart事件 As Chart

Private Sub Chart事件_MouseDown(ByVal Button As Long, ByVal Shift As Long, ByVal x As Long, ByVal y As Long)
    Debug.Print x, y
End Sub

需要用到这个类的工作表中写以下代码

Dim 新Chart类 As New Chart类
Private Sub Worksheet_Activate()
    Set 新Chart类.Chart事件 = ActiveSheet.ChartObjects(1).Chart
End Sub

Sub 结束事件连接()
    Set 新Chart类.Chart事件 = Nothing
End Sub

到此以经可以正常运行了,因为有时候要关联许多表,就要用到下面语句

Dim 新Chart类 As New Chart类

Dim 新Chart类s() As New Chart类

Private Sub xxxxxWorksheet_Activate()

    '如有必要

    '为表中的每一个图表建立秩序

    If ActiveSheet.ChartObjects.Count > 0 Then

        ReDim 新Chart类s(ActiveSheet.ChartObjects.Count)

        For Each chtObj In ActiveSheet.ChartObjects

            i = i + 1

            Set 新Chart类s(i).Chart事件 = chtObj.Chart

        Next

    End If

End Sub

Sub xxxxx结束事件连接()

    '如有必要

    '为表中的每一个图表断开连接

    Dim i As Integer

    On Error Resume Next

    Set clsEventChart.EvtChart = Nothing

    For i = 1 To UBound(clsEventCharts)

        Set clsEventCharts(i).EvtChart = Nothing

    Next

End Sub

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多