I have collected quite an assortment of macros over the last 2 years. Is
there a VBA method for counting how macros there are, with several modules
holding five or more macros?
Ed

Re: Can VBA count how many macros I have? by Michael

Michael
Wed Jul 27 22:09:01 CDT 2005

On Wed, 27 Jul 2005 15:59:40 -0700, "Ed" <ed_millis@NO_SPAM.yahoo.com>
wrote in microsoft.public.word.vba.general:

>I have collected quite an assortment of macros over the last 2 years. Is
>there a VBA method for counting how macros there are, with several modules
>holding five or more macros?

Try this: (needs a reference to "Microsoft Visual Basic for Applications
Extensibility" (VBE6EXT.OLB))

Sub CountMacros()

Dim objVBProj As VBProject
Dim objVBComps As VBComponents
Dim objVBComp As VBComponent
Dim objVBMod As CodeModule
Dim lngLine As Long

For Each objVBProj In VBE.VBProjects
Debug.Print "Project: " & objVBProj.Name
Set objVBComps = objVBProj.VBComponents
For Each objVBComp In objVBComps
Debug.Print " Component: " & objVBComp.Name
Set objVBMod = objVBComp.CodeModule
With objVBMod
lngLine = .CountOfDeclarationLines + 1
Do Until lngLine >= .CountOfLines
Debug.Print " Procedure: " & .ProcOfLine(lngLine, vbext_pk_Proc)
lngLine = lngLine + .ProcCountLines(.ProcOfLine(lngLine, vbext_pk_Proc), vbext_pk_Proc)
Loop
End With
Next objVBComp
Next objVBProj
End Sub

See also: <http://www.cpearson.com/excel/vbe.htm> and
<http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=307>.

--
Michael Bednarek http://mbednarek.com/ "POST NO BILLS"

Re: Can VBA count how many macros I have? by Ed

Ed
Thu Jul 28 10:39:30 CDT 2005

Very sweet! Thank you!!
Ed

"Michael Bednarek" <ROT13:abfcnz-zo@gtz.pbz.nh> wrote in message
news:feige1d13oiotbhebc4bsaruhmmecm9q82@4ax.com...
> On Wed, 27 Jul 2005 15:59:40 -0700, "Ed" <ed_millis@NO_SPAM.yahoo.com>
> wrote in microsoft.public.word.vba.general:
>
> >I have collected quite an assortment of macros over the last 2 years. Is
> >there a VBA method for counting how macros there are, with several
modules
> >holding five or more macros?
>
> Try this: (needs a reference to "Microsoft Visual Basic for Applications
> Extensibility" (VBE6EXT.OLB))
>
> Sub CountMacros()
>
> Dim objVBProj As VBProject
> Dim objVBComps As VBComponents
> Dim objVBComp As VBComponent
> Dim objVBMod As CodeModule
> Dim lngLine As Long
>
> For Each objVBProj In VBE.VBProjects
> Debug.Print "Project: " & objVBProj.Name
> Set objVBComps = objVBProj.VBComponents
> For Each objVBComp In objVBComps
> Debug.Print " Component: " & objVBComp.Name
> Set objVBMod = objVBComp.CodeModule
> With objVBMod
> lngLine = .CountOfDeclarationLines + 1
> Do Until lngLine >= .CountOfLines
> Debug.Print " Procedure: " & .ProcOfLine(lngLine,
vbext_pk_Proc)
> lngLine = lngLine + .ProcCountLines(.ProcOfLine(lngLine,
vbext_pk_Proc), vbext_pk_Proc)
> Loop
> End With
> Next objVBComp
> Next objVBProj
> End Sub
>
> See also: <http://www.cpearson.com/excel/vbe.htm> and
> <http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=307>.
>
> --
> Michael Bednarek http://mbednarek.com/ "POST NO BILLS"



Re: VBA count of macros: ERROR by Ed

Ed
Thu Jul 28 11:15:52 CDT 2005

Michael: I get a "Sub or Function not defined" error on:
lngLine = lngLine + .ProcCountLines(.ProcOfLine(lngLine,
vbext_pk_Proc), vbext_pk_Proc)
The offending item seems to be .ProcCountLines (at least, that's what gives
the error on mouse-over when the line is highlighted yellow).
I have the reference to VBA Extensibility 5.3 set. What else might I be
missing?
Ed

"Michael Bednarek" <ROT13:abfcnz-zo@gtz.pbz.nh> wrote in message
news:feige1d13oiotbhebc4bsaruhmmecm9q82@4ax.com...
> On Wed, 27 Jul 2005 15:59:40 -0700, "Ed" <ed_millis@NO_SPAM.yahoo.com>
> wrote in microsoft.public.word.vba.general:
>
> >I have collected quite an assortment of macros over the last 2 years. Is
> >there a VBA method for counting how macros there are, with several
modules
> >holding five or more macros?
>
> Try this: (needs a reference to "Microsoft Visual Basic for Applications
> Extensibility" (VBE6EXT.OLB))
>
> Sub CountMacros()
>
> Dim objVBProj As VBProject
> Dim objVBComps As VBComponents
> Dim objVBComp As VBComponent
> Dim objVBMod As CodeModule
> Dim lngLine As Long
>
> For Each objVBProj In VBE.VBProjects
> Debug.Print "Project: " & objVBProj.Name
> Set objVBComps = objVBProj.VBComponents
> For Each objVBComp In objVBComps
> Debug.Print " Component: " & objVBComp.Name
> Set objVBMod = objVBComp.CodeModule
> With objVBMod
> lngLine = .CountOfDeclarationLines + 1
> Do Until lngLine >= .CountOfLines
> Debug.Print " Procedure: " & .ProcOfLine(lngLine,
vbext_pk_Proc)
> lngLine = lngLine + .ProcCountLines(.ProcOfLine(lngLine,
vbext_pk_Proc), vbext_pk_Proc)
> Loop
> End With
> Next objVBComp
> Next objVBProj
> End Sub
>
> See also: <http://www.cpearson.com/excel/vbe.htm> and
> <http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=307>.
>
> --
> Michael Bednarek http://mbednarek.com/ "POST NO BILLS"



Re: VBA count of macros: ERROR by Michael

Michael
Thu Jul 28 21:36:17 CDT 2005

On Thu, 28 Jul 2005 09:15:52 -0700, "Ed" <ed_millis@NO_SPAM.yahoo.com>
wrote in microsoft.public.word.vba.general:

First a few things to your posting style:
1) Don't change the subject when you continue a thread; you might
never get a response.
2) Don't top-post when the previous contributor bottom-posted
(the preferred method).
3) Remove the signature of the previous posts.
4) Snip unnessesary line from previous posts.

>Michael: I get a "Sub or Function not defined" error on:
> lngLine = lngLine + .ProcCountLines(.ProcOfLine(lngLine,
>vbext_pk_Proc), vbext_pk_Proc)
>The offending item seems to be .ProcCountLines (at least, that's what gives
>the error on mouse-over when the line is highlighted yellow).
>I have the reference to VBA Extensibility 5.3 set. What else might I be
>missing?
[snip]

I hope you unwrapped the lines properly in case they got wrapped at your
end - they left here unwrapped and showed as such in my newsreader. Lines
which start in position 1 have been accidentally wrapped. All code below
starts in position 3 (plus indents).

I ran the macro in MS Word, Excel, and Access. There was a problem in
Excel with protected projects and apparently it needed the Application.
qualifier for the VBE.Projects object, so here is my amended code:

Sub CountMacros()

Dim objVBProj As VBProject
Dim objVBComps As VBComponents
Dim objVBComp As VBComponent
Dim objVBMod As CodeModule
Dim lngLine As Long

For Each objVBProj In Application.VBE.VBProjects
Debug.Print "Project: " & objVBProj.Name
If objVBProj.Protection = vbext_pp_none Then
Set objVBComps = objVBProj.VBComponents
For Each objVBComp In objVBComps
Debug.Print " Component: " & objVBComp.Name
Set objVBMod = objVBComp.CodeModule
With objVBMod
lngLine = .CountOfDeclarationLines + 1
Do Until lngLine >= .CountOfLines
Debug.Print " Procedure: " & .ProcOfLine(lngLine, vbext_pk_Proc)
lngLine = lngLine + .ProcCountLines(.ProcOfLine(lngLine, vbext_pk_Proc), vbext_pk_Proc)
Loop
End With
Next objVBComp
Else
Debug.Print " is protected."
End If
Next objVBProj

End Sub

--
Michael Bednarek http://mbednarek.com/ "POST NO BILLS"

Re: VBA count of macros: ERROR by Ed

Ed
Mon Aug 01 14:10:16 CDT 2005

Michael:
> First a few things to your posting style:
> 1) Don't change the subject when you continue a thread; you might
> never get a response.
> 2) Don't top-post when the previous contributor bottom-posted
> (the preferred method).
> 3) Remove the signature of the previous posts.
> 4) Snip unnecessary line from previous posts.
Sorry about the lapse in protocols.

The offending item seems to be a Class module that was given to me - it's
choking on the third procedure down, even in your amended code. It's not
that critical, so I used the Type in an If statement to bypass it. Now
everything runs fine.

I greatly appreciate your time and help with this.
Ed