From: Robin on
I may be getting my objects mixed up here, but this is the situation. I have
a document that has three sections. Each section has a different header and
footer with a different number linked images and other shapes in it. The
heading and footer used in an entire section is the same - no variations for
first page or numbered pages in that section.

When I count the number of shapes in each header/footer using the Count
property on the Shapes object, it tells me there are 16 shapes in each. This
is not correct, it is 16 for the entire document, so why is it not specific
for each section?

The code I have is as follows:



SubSub CleanHeader()

Dim s As Section
Dim j As Shape
Dim myRange As Range
Dim i As Integer
Dim n As Integer

' First we did a straight count on each section - they all gave 16 which is
wrong

MsgBox ("total 1: " &
ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes.Count)
MsgBox ("total 2: " &
ActiveDocument.Sections(2).Headers(wdHeaderFooterPrimary).Shapes.Count)
MsgBox ("total 3: " &
ActiveDocument.Sections(3).Headers(wdHeaderFooterPrimary).Shapes.Count)

' Then we did a systematic count - they also gave 16 which is wrong

For Each s In ActiveDocument.Sections
n = 0
For Each j In s.Headers(wdHeaderFooterPrimary).Shapes
n = n + 1
Next j
MsgBox ("total: " & n)
Next s

End Sub
Any help appreciated.

thanks
Robin
From: macropod on
Hi Robin,

That's because, when the headers are linked, the shapes exist in each header. Try:
Sub CleanHeader()
Dim rngScn As Section
Dim Shp As Shape
Dim i As Integer
For Each rngScn In ActiveDocument.Sections
i = 0
With rngScn.Headers(wdHeaderFooterPrimary)
If .LinkToPrevious = False Then i = .Shapes.Count
MsgBox "Section " & rngScn.Index & " primary header shapes total = " & i
End With
Next
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


"Robin" <Robin(a)discussions.microsoft.com> wrote in message news:0E2CD500-5A24-4E2A-B0BC-EA5F95B1D006(a)microsoft.com...
>I may be getting my objects mixed up here, but this is the situation. I have
> a document that has three sections. Each section has a different header and
> footer with a different number linked images and other shapes in it. The
> heading and footer used in an entire section is the same - no variations for
> first page or numbered pages in that section.
>
> When I count the number of shapes in each header/footer using the Count
> property on the Shapes object, it tells me there are 16 shapes in each. This
> is not correct, it is 16 for the entire document, so why is it not specific
> for each section?
>
> The code I have is as follows:
>
>
>
> SubSub CleanHeader()
>
> Dim s As Section
> Dim j As Shape
> Dim myRange As Range
> Dim i As Integer
> Dim n As Integer
>
> ' First we did a straight count on each section - they all gave 16 which is
> wrong
>
> MsgBox ("total 1: " &
> ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Shapes.Count)
> MsgBox ("total 2: " &
> ActiveDocument.Sections(2).Headers(wdHeaderFooterPrimary).Shapes.Count)
> MsgBox ("total 3: " &
> ActiveDocument.Sections(3).Headers(wdHeaderFooterPrimary).Shapes.Count)
>
> ' Then we did a systematic count - they also gave 16 which is wrong
>
> For Each s In ActiveDocument.Sections
> n = 0
> For Each j In s.Headers(wdHeaderFooterPrimary).Shapes
> n = n + 1
> Next j
> MsgBox ("total: " & n)
> Next s
>
> End Sub
> Any help appreciated.
>
> thanks
> Robin
From: Robin on
Hi Macropod,

I have tried what you suggested, but the counts are still the same across
all sections.

I then manually linked all sections in the document and could see the
document displaying "Same as previous" in the header. The shapes in section 2
and 3 disappeared and the macro displayed the first as having 13, the second
0 and the third 0. Really wierd?

thanks
Robin
From: macropod on
Hi Robin,

Try:
Sub CleanHeader()
Dim rngScn As Section, i As Integer
For Each rngScn In ActiveDocument.Sections
i = 0
With rngScn.Headers(wdHeaderFooterPrimary)
If .LinkToPrevious = False Then i = .Range.ShapeRange.Count
MsgBox "Section " & rngScn.Index & " primary header shapes total = " & i
End With
Next
End Sub

--
Cheers
macropod
[Microsoft MVP - Word]


"Robin" <Robin(a)discussions.microsoft.com> wrote in message news:E1636114-F6A8-4D03-96B1-D10DD71049B6(a)microsoft.com...
> Hi Macropod,
>
> I have tried what you suggested, but the counts are still the same across
> all sections.
>
> I then manually linked all sections in the document and could see the
> document displaying "Same as previous" in the header. The shapes in section 2
> and 3 disappeared and the macro displayed the first as having 13, the second
> 0 and the third 0. Really wierd?
>
> thanks
> Robin
From: Robin on
Hi Macropod,

No it's not working. I'm getting results of 0, 2 and 2 for the sections 1, 2
and 3 respectively and I know it should be 7, 3,10

The heading/footer content for each section are:
The first section with 7 consists of 6 linked images and 1 unlinked image.
The second has a linked image (applied via a quick list heading definition)
a line below the heading and a line above the footer (Word drawing elements).
The third section has eight text boxes and 2 linked images.

thanks
Robin