How to count the characters in header/footer?

P

Paresh

Can anybody give me the macro code to find the character count of the
contents in header/footer?

Thanks!

Paresh
 
D

Doug Robbins

MsgBox
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Characters.Count
MsgBox
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Characters.Count

It includes spaces and carriage returns.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
P

Paresh

Thanks for the tip.

Regards,
Paresh

Doug Robbins said:
MsgBox
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Characters.Count
MsgBox
ActiveDocument.Sections(1).Footers(wdHeaderFooterPrimary).Range.Characters.Count

It includes spaces and carriage returns.

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Greg

You could omit the count of spaces, line breaks and paragraph returns
with something like:

Sub CountCharacters()
Dim oChr As Range
Dim i As Long
For Each oChr In
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.Characters
Select Case Asc(oChr)
Case Is = 11, 13, 32 'The Asc Code for a paragraph, line break, and
space
i = i
Case Else
i = i + 1
End Select
Next
MsgBox "The header contains " & i & " characters."
End Sub
 

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