gwilym
asked on
List all procedures in a group
I have a very large group containing a number of projects, each with many forms, modules, class modules etc. I want a list of all the procedures - that's all the subs, properties and methods. How should I do this? Using VBIDE, by analyzing the files as text files, or is there a standard VB feature that I don't know of to do this for me?
Answers with working sample code please!
Answers with working sample code please!
You can use Object Browser (from View menu or by pressing F2 key). In the upper combo box select the name of your project. After that, the left list will contain the list of your forms/modules/classes and after clicking on one of them, the right pane will list the procedures/functions in the selected module.
You could create an Add-In and reference the VBIDE something like this:
Dim mvbProject As vbProject
Dim mvbComponent As VBComponent
Dim mvbCodeModule As CodeModule
Dim mvbCodePane As CodeModule
Dim mvbMember As Member
For Each mvbProject In VBInstance.VBProjects
MsgBox mvbProject.Name
For Each mvbComponent In mvbProject.VBComponents
MsgBox mvbComponent.Name
For Each mvbMember In mvbComponent.CodeModule.Me mbers
MsgBox mvbMember.Name & " - " & mvbMember.Type
Next
Next
Next
This will list all:
1. All Projects in the Open Group
2. All Forms,Modules and Classes in each Project
3. All properties, methods and members in each Form, Module or Class
It's a starting point for what you want to do. (I think)
Dim mvbProject As vbProject
Dim mvbComponent As VBComponent
Dim mvbCodeModule As CodeModule
Dim mvbCodePane As CodeModule
Dim mvbMember As Member
For Each mvbProject In VBInstance.VBProjects
MsgBox mvbProject.Name
For Each mvbComponent In mvbProject.VBComponents
MsgBox mvbComponent.Name
For Each mvbMember In mvbComponent.CodeModule.Me
MsgBox mvbMember.Name & " - " & mvbMember.Type
Next
Next
Next
This will list all:
1. All Projects in the Open Group
2. All Forms,Modules and Classes in each Project
3. All properties, methods and members in each Form, Module or Class
It's a starting point for what you want to do. (I think)
Give me your email address and i'll mail you an add-in dll that does that or raise the points to 300 and award with an A and I will mail you the source of an add-in that does that.
You should give the point to mcix. The answer is correct or is a very good aproach.
ASKER
Err .. thanks for the tip about the object browser. I did know that one! I need all the subs in all the projects, returned to code or a text file or something that I can manipulate for reports etc. For mcix's code - what is VBInstance? I couldn't see it listed under VBIDE, so I couldn't get the fragment to workas it just said unknown type. I've seen it mentioned in relation ot AddIns, but have no experience of them - I tried creating one with that fragment in but to no joy. What am I doing wrong to stop it working? I'm at g.ellis@dial.pipex.com if anyone feels like mailing sample code/a working VB project (writing the results out to an .xls would be just perfect!) because you could reach the dimbot stage with me where every time you tell me how to do it I mail back 'I can't get it to work ...'!
When you create an Add-In from the Add-In Template (VB5), it creates a project with the following declarations:
Public VBInstance As VBIDE.VBE
Public Connect As Connect
Connect is a class that is also created.
To use the code I provided,
1. Create an Add-In Project
2. On the Form it Creates, there will be an OK button
Paste the code in the OKButton_Click paste the code.
3. In the Immediate Window, Type AddToINI
4. Run the Project
5. Open a New Instance of VB
6. From the Add-In Menu, Add-In Manager...
Select MyAddIn
7. This should display a form with an OK and Cancel Button
8. Click On OK
You should get a series of ListBoxes.
I will look into making it more into a working example for you...
It might make more sense to put the results in an Access Database instead of an Excel spreadsheet. Atleast that is my thinking...
marko_justus@hotmail.com
Public VBInstance As VBIDE.VBE
Public Connect As Connect
Connect is a class that is also created.
To use the code I provided,
1. Create an Add-In Project
2. On the Form it Creates, there will be an OK button
Paste the code in the OKButton_Click paste the code.
3. In the Immediate Window, Type AddToINI
4. Run the Project
5. Open a New Instance of VB
6. From the Add-In Menu, Add-In Manager...
Select MyAddIn
7. This should display a form with an OK and Cancel Button
8. Click On OK
You should get a series of ListBoxes.
I will look into making it more into a working example for you...
It might make more sense to put the results in an Access Database instead of an Excel spreadsheet. Atleast that is my thinking...
marko_justus@hotmail.com
Implements IDTExtensibility
Private Sub Class_Initialize()
Load Form1
End Sub
Private Sub Class_Terminate()
Unload Form1
Set Form1 = Nothing
End Sub
Private Sub IDTExtensibility_OnAddInsU pdate(cust om() As Variant)
'
End Sub
Private Sub IDTExtensibility_OnConnect ion(ByVal VBInst As Object, ByVal ConnectMode As VBIDE.vbext_ConnectMode, ByVal AddInInst As VBIDE.AddIn, custom() As Variant)
'
Set Form1.m_vbe = VBInst
Form1.Show vbModal
End Sub
Private Sub IDTExtensibility_OnDisconn ection(ByV al RemoveMode As VBIDE.vbext_DisconnectMode , custom() As Variant)
Set Form1.m_vbe = Nothing
End Sub
Private Sub IDTExtensibility_OnStartup Complete(c ustom() As Variant)
'
End Sub
---- End Class--------------------- ---------- ---------- ---------- ---------- --------
--- Begin form1
Public m_vbe As VBIDE.vbe
Private Sub Command1_Click()
AddProjects m_vbe
End Sub
Private Sub AddProjects(ByVal vbe As VBIDE.vbe)
Dim vbp As VBIDE.VBProject
Dim tve As Node
For Each vbp In vbe.VBProjects
Set tve = TreeView1.Nodes.Add(, , , vbp.Name)
AddProjectComponents vbp, tve
Next
End Sub
Private Sub AddProjectComponents(ByVal vbp As VBIDE.VBProject, ByVal parenttve As Node)
Dim vbc As VBIDE.VBComponent
Dim tve As comctllib.Node
For Each vbc In vbp.VBComponents
Set tve = TreeView1.Nodes.Add(parent tve, tvwChild, , vbc.Name)
AddComponentFunctions vbc, tve
Next
End Sub
Private Sub AddComponentFunctions(ByVa l vbc As VBIDE.VBComponent, ByVal parenttve As Node)
Dim tve As comctllib.Node
Dim vbm As VBIDE.Member
For Each vbm In vbc.CodeModule.Members
Set tve = TreeView1.Nodes.Add(parent tve, tvwChild, , vbm.Name)
Next
End Sub
Private Sub Class_Initialize()
Load Form1
End Sub
Private Sub Class_Terminate()
Unload Form1
Set Form1 = Nothing
End Sub
Private Sub IDTExtensibility_OnAddInsU
'
End Sub
Private Sub IDTExtensibility_OnConnect
'
Set Form1.m_vbe = VBInst
Form1.Show vbModal
End Sub
Private Sub IDTExtensibility_OnDisconn
Set Form1.m_vbe = Nothing
End Sub
Private Sub IDTExtensibility_OnStartup
'
End Sub
---- End Class---------------------
--- Begin form1
Public m_vbe As VBIDE.vbe
Private Sub Command1_Click()
AddProjects m_vbe
End Sub
Private Sub AddProjects(ByVal vbe As VBIDE.vbe)
Dim vbp As VBIDE.VBProject
Dim tve As Node
For Each vbp In vbe.VBProjects
Set tve = TreeView1.Nodes.Add(, , , vbp.Name)
AddProjectComponents vbp, tve
Next
End Sub
Private Sub AddProjectComponents(ByVal
Dim vbc As VBIDE.VBComponent
Dim tve As comctllib.Node
For Each vbc In vbp.VBComponents
Set tve = TreeView1.Nodes.Add(parent
AddComponentFunctions vbc, tve
Next
End Sub
Private Sub AddComponentFunctions(ByVa
Dim tve As comctllib.Node
Dim vbm As VBIDE.Member
For Each vbm In vbc.CodeModule.Members
Set tve = TreeView1.Nodes.Add(parent
Next
End Sub
ASKER
I'd like to accpet mcix's comment as an answer if you can submit it as such - nothing personal, of the ones here and the ones I got mailed it was the one that I got to work straight off. With one exception - it doesn't list all the subs. The group that I used it on is very large - about 11 meg - and for, for instance, one of the classes which has about 60 public subs iterating through the collections described only returns three of them. For certain modules it works fine and lists all of them. Why is this? Is it just VB being crap, or am I doing something wrong?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It did actually work fine. I think the missing info was just a VB problem - restarting everything solved it and now it works every time, so maybe it was just the very large size of some of the modules that caused the problem. PS - do you know which property of vbMember will give me the parameters of all the methods that your code lists? (if necessary I can post this as a seperate Q)
Off the top of my head I don't know.
Post as a new question and maybe someone will...
Post as a new question and maybe someone will...