After reading the comments, I think you may find this answer helpful.
VBA does not support reflection, as @Monty Wild already mentioned, but adding links to Microsoft Visual Basic for Applications Extensibility 5.3 gives you access to the VBE object. You can then iterate over the object modules in the VBA project and extract all the code for the module in String format.
Consider the following (insert it into the new Module1 book)
Sub Main() Dim code As String code = GetCodeModule("Module1") Debug.Print code End Sub Private Function GetCodeModule(ByVal codeModuleName As String) As String Dim VBProj As VBIDE.VBProject Dim VBComp As VBIDE.VBComponent Dim CodeMod As VBIDE.CodeModule Set VBProj = ThisWorkbook.VBProject Set VBComp = VBProj.VBComponents(codeModuleName) Set CodeMod = VBComp.CodeModule GetCodeModule = CodeMod.Lines(1, CodeMod.CountOfLines) End Function
Now your code variable stores the exact code that is in your Module1 , you can check this by opening the Immediate Window ctrl + g .
You might want to write / use some Find function to parse the String components to get the names and values ββof the variables, but I would not recommend doing this, as this can become quite complicated.
user2140173
source share