hugefasad.blogg.se

Excel vba on event
Excel vba on event







excel vba on event

EvtChart = Nothing For chtnum = 1 To UBound ( clsEventCharts ) Set clsEventCharts ( chtnum ). Chart chtnum = chtnum + 1 Next ' chtObj End If End Sub ' ************************************************* ' Unhook the event classes from the charts Sub DisableEventsForAllCharts () ' Disable events for all charts previously enabled together Dim chtnum As Integer On Error Resume Next Set clsEventChart.

excel vba on event

ChartObjects Set clsEventCharts ( chtnum ). Count ) Dim chtObj As ChartObject Dim chtnum As Integer chtnum = 1 For Each chtObj In ActiveSheet. Count > 0 Then ReDim clsEventCharts ( 1 To ActiveSheet. EvtChart = ActiveSheet End If ' Enable events for all charts embedded on a sheet ' Works for embedded charts on a worksheet or chart sheet If ActiveSheet. Sub EnableEventsForAllCharts () ' Enable events on sheet if it is a chart sheet If TypeName ( ActiveSheet ) = "Chart" Then Set clsEventChart. This class module contains functions to handle event callbacks raised ' by the chart object when either the user or excel interacts with it. Option Explicit Dim clsEventChart As New CEventChart Dim clsEventCharts () As New CEventChart ' ************************************************* ' This function connects all chart objects in the currently active sheet to the event enabled ' class module CEventChart.

EXCEL VBA ON EVENT CODE

You should not need to modify this code at all and it can be left as is.

excel vba on event

This module handles the nitty gritty details of connecting/disconnecting the chart events in your workbook. ScreenUpdating = True End Sub ' + any other evens you want to subscribe to, see: '************* Your private functions go below this line Private Sub MyGreatFunction () ' You can access the chart object here by using the EvtChart object Debug. MyGreatFunction 'Enable screen updating again Application. ScreenUpdating = False ' TODO: Here comes your logic. MyGreatFunction End Sub Private Sub EvtChart_Calculate () ' Disable screen updating while the subroutine is run. users selects it) ' TODO: Here comes your logic. like MyGreatFunction below) Private Sub EvtChart_Activate () ' Executed whenever the chart is enabled (e.g. Option Explicit ' Declare object of type "Chart" with events ' This object will hold the Chart instance that is currently being manipulated Public WithEvents EvtChart As Chart ' *********** The Excel event functions go below this line, avoid having too much custom code in these functions ' rather have the event functions call them as private functions (e.g.









Excel vba on event