2
votes

First of all, I already found out how to list default event names of Excel UserForm Controls using Typelib Info referenced as TLBINF32.DLL.
I shared it here.
It is a part of my ongoing project to create codeflow diagrams and possibly VBA code obfuscator early alpha version available on GitHub.

The issue now, is, with trying to list Event Procedures of the UserForm itself:
Unlike listing UserForm Controls using TLI-ClassInfoFromObject(UserForm1.CommandButton1), I found out the hard way that I need to use TLI-TypeLibInfoFromFile("FM20.dll") because if I use ClassInfoFromObject(UserForm1), there is an error.

I also found out that I can use TLI-ClassInfoFromObject(ThisWorkbook.VBProject.VBComponents("UserForm1").Designer).
Using FM20.dll and .Designer methods both get 16 event procedure names.

I can manage/understand up to this far.

Then I manually counted the UserForm's event procedure dropdown list in Excel VBA Editor and found that there are 22 UserForm event procedures.
But after I ran the following code using TLI, the resulting list contains 16 event procedures only, as shown in the first photo.
I am using MSForms class/object from FM20.dll.
The code is as follows: (Needs Reference to TypeLib Information library at C:\Windows\SysWow64\TLBINF32.DLL)

Sub listUFEvents()
Dim t As TLI.TLIApplication
    Set t = New TLI.TLIApplication
Dim ti As TLI.TypeLibInfo
    Set ti = t.TypeLibInfoFromFile("C:\Windows\SysWOW64\FM20.dll")
Dim cci As TLI.CoClassInfo
Dim mi As TLI.MemberInfo
Dim i As Integer
    For Each cci In ti.CoClasses
        If cci.Name = "UserForm" Then
            For Each mi In cci.DefaultEventInterface.Members
                i = i + 1
                Debug.Print CStr(i), mi.Name
            Next mi
        End If
    Next cci
End Sub

6 events were not listed including UserForm.Activate and UserForm.QueryClose etc. comparison

My question is, why those 6 event procedures were not listed?
If these event procedures were not picked up from the TypeLib in FM20.dll, where do they come from?

Object Browser also shows only 16 procedures.

Or did I do something wrong in using TLI library?

I admit that I am pretty far from becoming/being an expert.
I am still trying to understand how TypeLib Info works.

How do I get all 22 event procedure names?

I need the event procedure names to differentiate user-defined procedures from the event procedures in a UserForm CodeModule in my project which is about listing the procedure calls in a VBA project.
I can't find anybody asking the same question anywhere either.

Edit:08FEB2021

  1. Added project userform image + zoomed one, to clearly show and better explain the question
  2. In the following zoomed photo,
    A->, UserForm controls' default event procedures' names
    B->, UserForm default event procedure names
    C->, User-defined Sub+Function residing inside UserForm CodeModule

my project zoomed Above image is zoomed for better clarity.
***********************************************************
I want to separate B from C like I did with A.
***********************************************************
So that we can know that default event procedures were NOT called directly.

The image below is presented to get a better idea of why I am needing to list the names of the UserForm event procedures. my project and question site

Apology
I apologize for being a bit political (if you wanna call a function name politics!).
I truly am sorry to have to involve a bit of politics here.
I am not asking for anything except your awareness. Give me a negative vote if you want, for doing what a man needs to do when his country needs him most.
I just want to do something, however small it may be, as a citizen of Myanmar.
Normally, I am not interested in politics but the current situation calls for me to let the world know that Myanmar is currently under siege by a Military coup which forcibly removed democratically elected government and currently oppressing its citizens' rights.
Please bear with me and I hope you all can understand and empathize with me.
Thanks for your kind understanding.

1
The 6 events which are not listed are the same 6 events you don't see when using WithEvents x As MSForms.UserForm in a class. These events are not members of a Userform. I would say these events are private events of a real made Userform in your VBA editor. - EvR
@EvR, thanks for the info. I appreciate it. Never wrote a class for userforms before. Good to know. Is there any method with which I can grab those 6 names, without hardcoding, of course? Do you think Excel/VBA must have them hard-coded or use a secret/private/unexposed method/structure to hold them? - Nay Lynn

1 Answers

0
votes

The TLBINF32.DLL does what it is designed (coded) to do, so there is nothing you can do to make it recognize the five events related to MSForm's multiple "open/close" steps, or the MSForm's own window's Resize events. If you want to use them in your code you can, for example, create string constants for the event names you need, or keep them in a lookup table in a worksheet, or in a text file you will read, or whichever other way that suites your project.

As for listing Excel UserForm Controls, you do not need TLBINF32.DLL at all because it's already built (obviously, since TLBINF32.DLL just taps into this) into the MSForm class. To test this, please create a form, name it, say, "Form1", throw in a few controls and run the following simple subroutine from anywhere within the VBA project:

Sub ExamineControls()
    Dim ctl As Control

    For Each ctl In Form1.Controls
        Debug.Print ctl.Name, ctl.Top, ctl.Visible '  anything else you need?
    Next
End Sub

It does not matter whether the Form1 is opened or not.

I hope this is helpful.