Re: How to Loop through document and gather statistics? by Russ
Russ
Sun Nov 04 00:29:30 PDT 2007
Al,
As you find each range that contains a sub or function, you could capture
the the range start number, also, to temporarily use in sorting a table by
the range start number.
.....When something is found then
load rDcm.Start along with sTmp & " (" & lPrg & ")" into adjoining table
cells.
Then after all the subroutines and functions are found, the column
containing the range start numbers could be used to sort the table and then
deleted if desired.
A TOC (table of contents) or bookmarks can be used for quickly going to the
start of particular subroutine or function in the document. Or your text in
the cells containing the names could be changed into crossreferences or
hyperlinks to jump to the corresponding text in the document.
> Helmut,
>
> This is really slick. Thanks!!
>
> Is there a way to look for both:
> .text = "Sub *End Sub" and
> .text = "Function *End Function"
> within the same search?
>
> I set up 2 searchs which works; however, I loose the sequence that the subs
> and functions as they are found in the document.
>
>
> "Helmut Weber" wrote:
>
>> Hi Al,
>>
>> Sub Macro2a()
>> Dim sTmp As String ' text of first paragraph in rDcm
>> Dim lPrg As Long ' number of paragraphs in rDcm
>> Dim rDcm As Range
>> Set rDcm = ActiveDocument.Range
>> With rDcm.Find
>> .Text = "Sub *End Sub"
>> .MatchWildcards = True
>> While .Execute
>> rDcm.Select ' for testing
>> sTmp = rDcm.Paragraphs(1).Range.Text
>> sTmp = Left(sTmp, Len(sTmp) - 1)
>> lPrg = rDcm.Paragraphs.Count
>> MsgBox sTmp & " (" & lPrg & ")"
>> Wend
>> End With
>> End Sub
>>
>> Note that rDcm collapses to the found range
>> and expands again from the found range to
>> the end of the doc automatically.
>>
>> Of course, this depends on the regularity of you code.
>>
>> There are lots of ways for improvement.
>> You may search for chr(13) & "Sub "
>> (Which would not process the first paragraph in the doc,
>> if that first paragraph starts with "Sub") :-(
>> You may search for chr(13) & "Public Sub "
>> You may search for chr(13) & "Private Sub "
>> You may define the end of a sub as "End Sub" & chr(13) etc.
>>
>> --
>> Greetings from Bavaria, Germany
>>
>> Helmut Weber, MVP WordVBA
>>
>> Win XP, Office 2003
>> "red.sys" & Chr$(64) & "t-online.de"
>>
>>
>>
--
Russ
drsmN0SPAMikleAThotmailD0Tcom.INVALID