Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Listing all UDFs, Classes, methods etc..

Hi there

Having written a large number of UDFs and Classes with their
associated Properties & Methods I was wondering if rather than
manually typing them all into a spreadsheet is there a way I can get
VBA to do this automatically for me?

So for example, the code would search through the current open
projects, note the various functions & subs in Modules and Class
Modules and list them all on a new sheet.

I'm sure this would be quite useful for a lot of people.

Many Thanks
Lloyd

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Listing all UDFs, Classes, methods etc..

Lloyd,

Try the macro below. It requires a reference to MS VBA Extensibility.

HTH,
Bernie
MS Excel MVP

Sub ListFunctionsAndSubs()

Dim myBook As Workbook

Dim myStartLine As Long
Dim NumLines As Long

Dim ProcName As String
Dim VBComp As VBComponent
Dim RowNdx As Long

Cells(1, 1).Value = "Workbook Name"
Cells(1, 2).Value = "Module Name"
Cells(1, 3).Value = "Procedure Name"
Cells(1, 4).Value = "Type"
Cells(1, 5).Value = "Start Line"
Cells(1, 6).Value = "Number of Lines"

RowNdx = 2
For Each myBook In Application.Workbooks
For Each VBComp In myBook.VBProject.VBComponents
If VBComp.Type = vbext_ct_StdModule Then
NumLines = 0
With VBComp.CodeModule
myStartLine = .CountOfDeclarationLines + 1
While myStartLine + NumLines < .CountOfLines
ProcName = .ProcOfLine(myStartLine, vbext_pk_Proc)
Cells(RowNdx, 1).Value = myBook.Name
Cells(RowNdx, 2).Value = VBComp.Name
Cells(RowNdx, 3).Value = ProcName
If .Find("Fun", myStartLine, 1, myStartLine, 100, False, False, False) Then
myType = "Function"
Else: myType = "SubRoutine"
End If
Cells(RowNdx, 4).Value = myType
Cells(RowNdx, 5).Value = myStartLine
NumLines = .ProcCountLines(ProcName, vbext_pk_Proc)
Cells(RowNdx, 6).Value = NumLines
myStartLine = myStartLine + NumLines
RowNdx = RowNdx + 1
Wend
End With
End If

Next VBComp
Next myBook
End Sub




"pinkfloydfan" wrote in message
ups.com...
Hi there

Having written a large number of UDFs and Classes with their
associated Properties & Methods I was wondering if rather than
manually typing them all into a spreadsheet is there a way I can get
VBA to do this automatically for me?

So for example, the code would search through the current open
projects, note the various functions & subs in Modules and Class
Modules and list them all on a new sheet.

I'm sure this would be quite useful for a lot of people.

Many Thanks
Lloyd



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Listing all UDFs, Classes, methods etc..

Thanks Bernie that's cool!

Now as I am not familiar with what the VBA Extensibility does or how
to use the Type VBComponent...how do we improve this to cover
ClassModules and list their various parts..?

Cheers
Lloyd

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Listing all UDFs, Classes, methods etc..

Lloyd,

You will need to expand this part:

If .Find("Fun", myStartLine, 1, myStartLine, 100, False, False, False) Then
myType = "Function"
Else
myType = "SubRoutine"
End If

to include items that you want to look for, like Property Let and Property Get statements. "That is
left as an exercise for the student..." ;-)

HTH,
Bernie
MS Excel MVP


Sub ListFunctionsAndSubs2()

Dim myBook As Workbook

Dim myStartLine As Long
Dim NumLines As Long

Dim ProcName As String
Dim VBComp As VBComponent
Dim RowNdx As Long

On Error Resume Next

Cells(1, 1).Value = "Workbook Name"
Cells(1, 2).Value = "Module Name"
Cells(1, 3).Value = "Module Type"
Cells(1, 4).Value = "Procedure Name"
Cells(1, 5).Value = "Type"
Cells(1, 6).Value = "Start Line"
Cells(1, 7).Value = "Number of Lines"

RowNdx = 2
For Each myBook In Application.Workbooks
For Each VBComp In myBook.VBProject.VBComponents
If VBComp.Type = vbext_ct_StdModule Or VBComp.Type = vbext_ct_ClassModule Then
NumLines = 0
With VBComp.CodeModule
myStartLine = .CountOfDeclarationLines + 1
While myStartLine + NumLines < .CountOfLines
ProcName = .ProcOfLine(myStartLine, vbext_pk_Proc)
Cells(RowNdx, 1).Value = myBook.Name
Cells(RowNdx, 2).Value = VBComp.Name
Cells(RowNdx, 3).Value = IIf(VBComp.Type = vbext_ct_ClassModule, "Class Mod", "Std
Mod")
Cells(RowNdx, 4).Value = ProcName
If .Find("Fun", myStartLine, 1, myStartLine, 100, False, False, False) Then
myType = "Function"
Else
myType = "SubRoutine"
End If
Cells(RowNdx, 5).Value = myType
Cells(RowNdx, 6).Value = myStartLine
NumLines = .ProcCountLines(ProcName, vbext_pk_Proc)
Cells(RowNdx, 7).Value = NumLines
myStartLine = myStartLine + NumLines
RowNdx = RowNdx + 1
Wend
End With
End If

Next VBComp
Next myBook
End Sub

--
HTH,
Bernie
MS Excel MVP


"pinkfloydfan" wrote in message
ps.com...
Thanks Bernie that's cool!

Now as I am not familiar with what the VBA Extensibility does or how
to use the Type VBComponent...how do we improve this to cover
ClassModules and list their various parts..?

Cheers
Lloyd



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default Listing all UDFs, Classes, methods etc..

See www.cpearson.com/excel/vbe.htm#ListAllInProject and
www.cpearson.com/excel/vbe.htm#ProcDeclaration for example code to list all
procedures, methods, and properties of objects defined in a project, and to
list the declarations of properties and methods.



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)



"pinkfloydfan" wrote in message
ups.com...
Hi there

Having written a large number of UDFs and Classes with their
associated Properties & Methods I was wondering if rather than
manually typing them all into a spreadsheet is there a way I can get
VBA to do this automatically for me?

So for example, the code would search through the current open
projects, note the various functions & subs in Modules and Class
Modules and list them all on a new sheet.

I'm sure this would be quite useful for a lot of people.

Many Thanks
Lloyd





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Listing all UDFs, Classes, methods etc..

There's also the MZ-Tools addin, which has a number of Utilities for
analysing your code, especially the pretty detailed "Generate XML
Documentation".
http://www.mztools.com/index.htm

NickHK

"pinkfloydfan" wrote in message
ups.com...
Hi there

Having written a large number of UDFs and Classes with their
associated Properties & Methods I was wondering if rather than
manually typing them all into a spreadsheet is there a way I can get
VBA to do this automatically for me?

So for example, the code would search through the current open
projects, note the various functions & subs in Modules and Class
Modules and list them all on a new sheet.

I'm sure this would be quite useful for a lot of people.

Many Thanks
Lloyd



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 68
Default Listing all UDFs, Classes, methods etc..

Thanks everybody this has been really helpful

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Automation Classes / Methods, overview or list Ole Schjoeth Excel Discussion (Misc queries) 2 November 27th 06 08:14 PM
UDFs in Excel VBAnewbie Excel Programming 6 August 11th 06 03:36 PM
Replacing UDFs with their value Dave Moran Excel Programming 4 June 23rd 06 01:30 PM
UDFs DoctorG Excel Programming 3 July 5th 05 01:49 PM
Where do I find the listing of the differnt methods, properties etc used by VBA? Phillips Excel Programming 1 December 9th 03 11:42 AM


All times are GMT +1. The time now is 06:12 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"