Critical Problem: Headers and wordcount

M

Mandy Dhaliwal

Dear all,
I am using VB6 and I want to do the following
(1)get the linecount of the any word/rtf file
(2)It should include lines in header and footer also

Please help me out
 
D

Doug Robbins - Word MVP

Hi Mandy,

Use the ComputeStatistics function as follows

Dim i As Integer, arange As Range, j As Integer
i = ActiveDocument.ComputeStatistics(wdStatisticLines)
For j = 1 To ActiveDocument.Sections.Count
If
Len(ActiveDocument.Sections(j).Headers(wdHeaderFooterFirstPage).Range) > 1
Then
i = i +
ActiveDocument.Sections(j).Headers(wdHeaderFooterFirstPage).Range.ComputeSta
tistics(wdStatisticLines)
End If
If Len(ActiveDocument.Sections(j).Headers(wdHeaderFooterPrimary).Range)
i = i +
ActiveDocument.Sections(j).Headers(wdHeaderFooterPrimary).Range.ComputeStati
stics(wdStatisticLines)
End If
If
Len(ActiveDocument.Sections(j).Footers(wdHeaderFooterFirstPage).Range) > 1
Then
i = i +
ActiveDocument.Sections(j).Footers(wdHeaderFooterFirstPage).Range.ComputeSta
tistics(wdStatisticLines)
End If
If Len(ActiveDocument.Sections(j).Footers(wdHeaderFooterPrimary).Range)
i = i +
ActiveDocument.Sections(j).Footers(wdHeaderFooterPrimary).Range.ComputeStati
stics(wdStatisticLines)
End If
Next j
MsgBox i & " lines"

Once you have a single header or footer in a section, the other header
footer possibilities (First Page/Primary) get counted as containing a single
line, even if they are empty, hence checking the length of the range.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
M

Mandy Dhaliwal

Dear Doug Robbins,
Thankyou very much for your help.The code sent by you worked.One thing
more can I use this Word API in in VC++?if yes please give me some
URLs.
Thanks a lot.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top