vendredi 30 septembre 2022

How to iterate through the members of a standard module

My goal is to list the procedures exposed by the compiled VBProject, as visible in the Excel Macros menu or when typing a cell formula which makes appear availble UDF. A Solution that list any member (Enum, Sub, Function, etc.) of a CodeModule or of the full VBProject would be ideal.

I am not looking for a code parsing solution.

I could find old mentions of a way to do so in VB with the VBIDE library, which ( should / used to ) expose a VBIDE.Member class (accessible via the CodeModule.Members property) with those interesting properties:

Member.Name As String
Member.Type As VBIDE.vbext_MemberType
Member.Scope As VBIDE.vbext_Scope

For a reason I don't understand, I cannot access them via VBA and the VBIDE library, there are not even listed as hidden members.

Is there a way to get them? Rubberduck (previously known as Mat's Mug heon Stack Overflow) aka Mathieu Guindon suggests it is possible though: https://rubberduckvba.wordpress.com/2016/03/24/a-reflection-on-vba-reflection/

Another idea: how to use Reflection with VBA? Again, he suggests it is possible: https://rubberduckvba.wordpress.com/2019/04/10/whats-wrong-with-vba/

Note: the Rubberduck COM Add-In that integrates with the VBE, is able to do it (using .NET as I understand it)





Aucun commentaire:

Enregistrer un commentaire