Answers gratefully received
Thanks
James
Sub FindMacros()
Dim vbComp As VBIDE.VBComponent
Dim wb As Workbook
Set wb = ThisWorkbook
For Each vbComp In wb.VBProject.VBComponents
Debug.Print vbComp.Type & " " & vbComp.Name
Next
End Sub
Download my VBA Code Documentor utility from the web site below my sig.
The code is unprotected, so you can dig in and see how it works.
--
Rob Bovey, Excel MVP
Application Professionals
http://www.appspro.com/
* Take your Excel development skills to the next level.
* Professional Excel Development
http://www.appspro.com/Books/Books.htm
"James Price" <James Pr...@discussions.microsoft.com> wrote in message
news:60FDBD76-87C7-4C54...@microsoft.com...
'---------------------------------------------------------------
Public Function ListMacros(Optional RunTypesOnly As Boolean = True, _
Optional PublicOnly As Boolean = False)
'---------------------------------------------------------------
' Function: List all macros in all workbook projects
' Synopsis: Loops through the designated module processing
' each procedure by:
' - get the number of lines in the procedure
' - searches for the End statement in procedure
' to identify its line number
' - determines the procedure type
' - move onto next procedure
'---------------------------------------------------------------
Const COMPONENT_MODULE As Long = 1
Dim oCodeModule As Object, oComponent As Object
Dim oWb As Workbook
Dim fStart As Boolean
Dim iStart As Long, iCurrent As Long
Dim cLines As Long, cProcs As Long
Dim ProcType As Long '0 Property, 1 Sub, 2 Function
Dim sProcName As String
Dim lProcKind As Long
Dim aryProcs
ReDim aryProcs(1 To 3, 1 To 1)
For Each oWb In Application.Workbooks
Debug.Print oWb.Name
For Each oComponent In oWb.VBProject.VBComponents
Debug.Print "___" & oComponent.Name
If oComponent.Type = COMPONENT_MODULE Then
With oComponent.CodeModule
iStart = .CountOfDeclarationLines + 1
Do Until iStart >= .CountOfLines
'get the procedure name and count of line
'.ProcOfLine modifies ProcKind to type
sProcName = .ProcOfLine(iStart, lProcKind)
cLines = .ProcCountLines(sProcName, lProcKind)
Debug.Print "______" & sProcName
iCurrent = iStart - 1
Do
iCurrent = iCurrent + 1
fStart = .Lines(iCurrent, 1) Like "*Sub *" Or _
.Lines(iCurrent, 1) Like "*Function *"
Or _
.Lines(iCurrent, 1) Like "*Property *"
Loop Until fStart
'determine procedure type
If .Lines(iCurrent, 1) Like "*Sub *" Or _
.Lines(iCurrent, 1) Like "*Function *" Then
If Not PublicOnly Or Not .Lines(iCurrent, 1)
Like "*Private *" Then
If RunTypesOnly Then
If InStr(.Lines(iCurrent, 1), "()") Then
cProcs = cProcs + 1
ReDim Preserve aryProcs(1 To 3, 1 To
cProcs)
aryProcs(1, cProcs) = oWb.Name
aryProcs(2, cProcs) =
oComponent.Name
aryProcs(3, cProcs) = sProcName
End If
Else
cProcs = cProcs + 1
ReDim Preserve aryProcs(1 To 3, 1 To
cProcs)
aryProcs(1, cProcs) = oWb.Name
aryProcs(2, cProcs) = oComponent.Name
aryProcs(3, cProcs) = sProcName
End If
End If
End If
'onto the next procedure
iStart = iStart + _
.ProcCountLines(sProcName, lProcKind)
Loop
End With 'oComponent
End If
Next oComponent
Next oWb
ListMacros = aryProcs
End Function
--
HTH
Bob Phillips
"James Price" <James Pr...@discussions.microsoft.com> wrote in message
news:60FDBD76-87C7-4C54...@microsoft.com...
I like to think I know a little about MS Visio - if per chance you have a
query please feel free to contact me at jam...@premiercs.co.uk
Cheers
James
James
urls are
'Documented in http://www.mvps.org/dmcritchie/excel/buildtoc.htm
'Coding: http://www.mvps.org/dmcritchie/excel/code/listfsubs.txt
'Coding: http://www.mvps.org/dmcritchie/excel/code/buildtoc.txt
'Coding: http://www.mvps.org/dmcritchie/excel/code/gotostuff.txt
'My Excel Macros: http://www.mvps.org/dmcritchie/excel/excel.htm
I think the first url will give your the other links.
-
remove $$$ from email addresss to send email
=======================
Elizabeth <Eliz...@discussions.microsoft.com> wrote in message
news:516E72F9-258A-46C3...@microsoft.com...
When I place my cursor on VBComponent & hit F1, Microsoft VB Help returns
"Keyword Not Found". I am not familiar with this property & cannot locate it
in 3 reference books I have.
Am I just too new at VBA to make this work, or is there a simple reason /
solution to this. Thanks again.
Elizabeth
To do this, in the vba goto tools, references and find the one above and
check it.
James
"Elizabeth" <Eliz...@discussions.microsoft.com> wrote in message
news:154DDB89-4B08-43F0...@microsoft.com...
This is a user by user setting (FYI). If you change your setting, it doesn't
affect anybody else.
--
Dave Peterson
--
HTH
Bob Phillips
"James Wellington" <james_we...@comcast.net> wrote in message
news:%23IUIqrE...@TK2MSFTNGP10.phx.gbl...
Bob
"Elizabeth" <Eliz...@discussions.microsoft.com> wrote in message
news:6A097818-4A90-4B6A...@microsoft.com...