3

グローバルイベントリスナーのようなものを書くことは可能ですか? より多くのオブジェクト (TextBox、CheckBox、OptionButton、Label など) のリスナーが必要です。私のクラスにリスナーがいます。通常のイベントがいくつかあるので、私の考えは次のようになります。

Public WithEvents eventGlobLst As <DontKnowWhat>SomeType</DontKnowWhat>

Sub setListener(controlObj As SomeType)
  Set eventGlobList = controlObj 
End Sub

run-method から、リスナーを設定する sub を呼び出しています

For Each pages In csDialgog.MultiPage.Pages
    For Each objectControl In pages.Controls

        Set eventClass = New ControlsClass
        eventClass.setListener objectControl
        universalObjectCollection.Add eventClass 
    Next
Next

これは、従来のイベントでうまく機能します。最後に、いくつかのイベント ハンドラーがあります。

Private Sub EventGlobLstnr_AfterUpdate()
    Functions.GlobalChange
End Sub

私が使用できるすべてのオブジェクトの祖先が存在するかどうかを知りたいです。または、すべてのタイプのリスナーを個別に作成し、それらを同じに設定する必要がありますGlobalChange

4

1 に答える 1

0

The answer is no, you're probably better off with self-writing code. Here's a good link that allows you to write into VBA editor

Programming the VBA editor - Chip Pearson

This code was taken from Chip Pearson:
Creating An Event Procedure

This code will create a Workbook_Open event procedure. When creating an event procedure, you should use the CreateEventProc method so that the correct procedure declaration and parameter list is used. CreateEventProc will create the declaration line and the end of procedure line. It returns the line number on which the event procedure begins.

Sub CreateEventProcedure()
    Dim VBProj As VBIDE.VBProject
    Dim VBComp As VBIDE.VBComponent
    Dim CodeMod As VBIDE.CodeModule
    Dim LineNum As Long
    Const DQUOTE = """" ' one " character

    Set VBProj = ActiveWorkbook.VBProject
    Set VBComp = VBProj.VBComponents("ThisWorkbook")
    Set CodeMod = VBComp.CodeModule

    With CodeMod
        LineNum = .CreateEventProc("Open", "Workbook")
        LineNum = LineNum + 1
        .InsertLines LineNum, "    MsgBox " & DQUOTE & "Hello World" & DQUOTE
    End With
End Sub

Using .CreateEventProc, you can create an event for each elements that you want to "catch"
I believe this is the only way of achieving the goal you want.

Cheers,
kpark

于 2013-08-22T16:15:31.747 に答える