Need the first line of the VBA code of all my UDF

SeniorNewbie

Board Regular
Joined
Jul 9, 2023
Messages
77
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
  2. MacOS
Hi! out there,

with this little snippet I'm able to list all userdefined functions to a worksheet:
VBA Code:
Option Explicit

Public Sub ListProcedures()
Dim oMod As Object
Dim i As Integer, iStart As Integer

Cells.Clear

i = 1
For Each oMod In ActiveWorkbook.VBProject.VBComponents
    With oMod.CodeModule
        If oMod.Name = "mdlFunctions" Then
            iStart = .CountOfDeclarationLines + 1
            Do Until iStart >= .CountOfLines
                Cells(i, 1) = .ProcOfLine(iStart, 0)
                Cells(i, 2) = oMod.Type & "*"
                Cells(i, 3) = oMod.Name
                iStart = iStart + .ProcCountLines(.ProcOfLine(iStart, 0), 0)
                i = i + 1
            Loop
        End If
    End With
Next

End Sub
As you'll understand I'll get the name and the type of the procedure. What I need is the entire first line of the code e.g. Public Function KissMe(Sound as a String, Duration as Long, Taste as Byte)

I guess that it's only one line more in my code, but so far I'm helpless.

Thank you very much and have a nice weekend!

Newbie sr.


EDIT:
btw &fyi: Types are listed as:
100 = code in a sheet
1 = subs AND functions
3 = events in a userform
 
Last edited by a moderator:

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Try the following...

VBA Code:
Option Explicit

Public Sub ListProcedures()
Dim oMod As Object
Dim i As Long, j As Long, iStart As Long

Cells.Clear

i = 1
For Each oMod In ActiveWorkbook.VBProject.VBComponents
    With oMod.CodeModule
        If oMod.Name = "mdlFunctions" Then
            iStart = .CountOfDeclarationLines + 1
            Do Until iStart >= .CountOfLines
                Cells(i, 1).Value = .ProcOfLine(iStart, 0)
                Cells(i, 2).Value = oMod.Type & "*"
                Cells(i, 3).Value = oMod.Name
                j = iStart
                Do While Len(.Lines(j, 1)) = 0
                    j = j + 1
                Loop
                Cells(i, 4).Value = .Lines(j, 1)
                iStart = iStart + .ProcCountLines(.ProcOfLine(iStart, 0), 0)
                i = i + 1
            Loop
        End If
    End With
Next

End Sub

Hope this helps!
 
Upvote 0
Solution

Forum statistics

Threads
1,226,695
Messages
6,192,475
Members
453,726
Latest member
JoeH57

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top