2

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.

Nay Lynn
  • 351
  • 1
  • 12
  • 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 Feb 07 '21 at 23:18
  • @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 Feb 08 '21 at 01:39

1 Answers1

0

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.

  • Think OP wanted to collect the names of all existing event procedures, not assigned contents of ctrl properties :-; – T.M. Feb 07 '21 at 19:06
  • @T.M. -- So, really, what is it you did not understand in my answer? Could you elaborate, please? The question was: "My question is, why those 6 event procedures were not listed? Or did I do something wrong in using TLI library?" –  Feb 07 '21 at 20:06
  • @T.M., you're right. I just wanted to list the names of the existing event procedures. ctrl properties, on the other hand, I can manage easily. I also found the ctrl properties in the typelib info too. They are usually found as the first interface's members of a coclass, mixed with other stuff, sometimes, while the events are located in the second interface, i.e. if you use classinfofrom object method. And thanks for your kind answer and support. – Nay Lynn Feb 08 '21 at 01:45
  • @Gene, thanks for your kind answer. Sorry I confused you. My fault. Added 2 photos to better clarify my question. First, TLBINF32 must be doing it's job, the problem is me. Still learning, so I thought I didn't call the correct procedure/correct parameters so getting a garbage output. Second, like you said, I can hardcode those 6 names while getting the other 16 using typelib. I just want to know 1)why only 16 were listed, 2)where does other 6 procedure names come from, were they hardcoded by Excel too?, 3) are those 6, part of something that I can extract somehow? Thanks for listing controls. – Nay Lynn Feb 08 '21 at 02:02
  • @Gene, If called as a sub, OK. Try reading control names like that in a sub without calling as a sub. If userform is loaded, it's OK, if NOT, you'll need .Designer.Controls because the controls are on the Designer. In Watch window:(3. needs Ref to Extensibility and Trust VBA OBJ Model) after `Load UserForm1` 1.`for each c in UserForms(0).controls:Print c.name:next` 2.`for each c in UserForms("UserForm1").controls:Print c.name:next` 3.`for each c in thisworkbook.VBProject.VBComponents("UserForm1").Designer.controls: Print c.name:next` Call again after `Unload UserForm1` – Nay Lynn Feb 08 '21 at 03:57
  • @Nay Lynn, If you use UserForms collection then you do need the form loaded to work with it. Pls note that I used the Code Name of the form; this way it's all there regardless. –  Feb 08 '21 at 19:53
  • @Nay Lynn, As for getting the other 6 event names, I do not know what can be done directly programmatically. Hardcoding will work, esp. since the same objects will always have the same set of events. Unfortunately, there are many objects... –  Feb 08 '21 at 19:57
  • @Gene, since you used the codename of the userform, as soon as the compiler sees that codename, it GOT loaded, that's why you don't need the userform loaded. Generally, getting a userform loaded may not be a problem. But since I am required to go through VBComponents, if the userform got loaded, I can't use .Designer anymore. Well, with more than 1 and possibly likely renamed userforms, I don't have the luxury of using codenames. Thanks anyway. – Nay Lynn Feb 09 '21 at 01:28
  • @Gene, I agree with you on the the matter of the remaining 6 event names. So far, I have no idea how to get them, apart from Hardcoding them, like you said, in addition to the other 16. Fortunately, concerning the limited scope of my project, UserFom is the last issue I have. Thanks for sharing your kind insight and advice. I really appreciate it. – Nay Lynn Feb 09 '21 at 01:38