
Signature
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
More comprehensive, perhaps, but not a complete check.
Every section always has three header and three footer *objects* which may
or may not have content. Whether or not they are in use is indicated by the
somewhat paradoxical Exists property.
The check on the Range, therefore, should be conditional upon the Exists
property being true.
Sub HFExists()
Dim s As Section
Dim hf As HeaderFooter
Dim Flag As Boolean
For Each s In ActiveDocument.Sections
For Each hf In s.Headers
If hf.Exists Then
If Len(hf.Range.Text) > 1 Then
Flag = True
End If
End If
Next
For Each hf In s.Footers
If hf.Exists Then
If Len(hf.Range.Text) > 1 Then
Flag = True
End If
End If
Next
Next
If Flag Then
MsgBox "A header of footer was found."
Else
MsgBox "There is no header or footer."
End If
End Sub
--
Enjoy,
Tony
> Hi Greg,
>
[quoted text clipped - 62 lines]
> >>> Is it possible to detect whether a header/footer is present in the
> >>> activedoc
Jonathan West - 28 Nov 2005 14:33 GMT
Things get even more complicated by the fact that while a header or footer
might exist, it might not be displayed in a particular section.
The first page header & footer will not display if the
PageSetup.DifferentFirstPageHeaderFooter property of the Section is False
The even pages header will not display if the
PageSetup.OddAndEvenPagesHeaderFooter property of the Section is False.

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Keep your VBA code safe, sign the ClassicVB petition www.classicvb.org
> More comprehensive, perhaps, but not a complete check.
>
[quoted text clipped - 107 lines]
>> >>> Is it possible to detect whether a header/footer is present in the
>> >>> activedoc
Greg - 28 Nov 2005 15:17 GMT
Jonathan,
It is quite possible that I have just dined on crow and don't quite
follow the OPs intent.
Tony Jollans - 28 Nov 2005 17:04 GMT
Jonathon,
Aren't you just stating the same as I did in a different way?
However, it made me wonder about another situation - what if there are two
different headers set up in a section, say a first page header with no
content and one for all other pages with some content. Ignoring
complications like continuous section breaks, if the section only has one
page it will have no visible header.
--
Enjoy,
Tony
> Things get even more complicated by the fact that while a header or footer
> might exist, it might not be displayed in a particular section.
[quoted text clipped - 123 lines]
> >> >>> Is it possible to detect whether a header/footer is present in the
> >> >>> activedoc
Greg - 28 Nov 2005 15:07 GMT
Tony,
While the method you proposed is certainly comprehensive and complete,
I don't see it as more complete than the method I suggested.
The simple fact that a header or footer storylength > 1 confirms that a
header or footer exists and sets the flag to answer the OPs questions.
Once that question is answered there is no need to continue processing.
Actually checking the .Exists condition is rather pointless. Consider
a new blank document and run the following code:
Sub HFExists()
Dim s As Section
Dim hf As HeaderFooter
Dim Flag As Boolean
For Each s In ActiveDocument.Sections
For Each hf In s.Headers
If hf.Exists Then Flag = True
Exit For
Next
Next
If Flag Then
MsgBox "A header exits."
Else
MsgBox "There is no header."
End If
End Sub
Tony Jollans - 28 Nov 2005 17:13 GMT
Hi Greg,
Yes, you are right about early termination of the loop - in that sense your
code is better than mine but I think you have missed the point that a header
or footer may have content but be flagged with ".exists = false" and
therefore not play any part in the make up of the complete document.
--
Enjoy,
Tony
> Tony,
>
[quoted text clipped - 24 lines]
> End If
> End Sub