Does anyone know why shapes in the header or footer story ranges are treated
differently than shapes contained in the main text story?

If I put two shapes containing text (text containing one spelling error) in
the main text story and two shapes containing similar text in the header of
a document and run this code:

Sub CheckForErrors1()
Dim pRange As Word.Range
Dim oShp As Shape
Dim i As Long
For Each pRange In ActiveDocument.StoryRanges
Do
i = i + pRange.SpellingErrors.Count
Set pRange = pRange.NextStoryRange
Loop Until pRange Is Nothing
Next
MsgBox i
End Sub

This msgbox response is 2.

The correct response should be 4 which is the results of running this code:

Sub CheckForErrors2()
Dim pRange As Word.Range
Dim oShp As Shape
Dim i As Long
For Each pRange In ActiveDocument.StoryRanges
Do
Select Case pRange.StoryType
Case 6, 7, 8, 9, 10, 11
i = i + pRange.SpellingErrors.Count
If pRange.ShapeRange.Count > 0 Then
For Each oShp In pRange.ShapeRange
If oShp.TextFrame.HasText Then
i = i + oShp.TextFrame.TextRange.SpellingErrors.Count
End If
Next oShp
End If
Case Else
i = i + pRange.SpellingErrors.Count
End Select
Set pRange = pRange.NextStoryRange
Loop Until pRange Is Nothing
Next
MsgBox i
End Sub

Why do shapes in storyrange type 6, 7, 8, 9, 10 and 11 have to be treated
separately and individually?

Thanks.


--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

Re: Header and Footer StoryRanges by Jonathan

Jonathan
Fri Nov 30 05:16:37 PST 2007


"Greg Maxey" <gmaxey@mvps.oSCARrOMEOgOLF> wrote in message
news:%23O3tHI1MIHA.4136@TK2MSFTNGP03.phx.gbl...
> Does anyone know why shapes in the header or footer story ranges are
> treated differently than shapes contained in the main text story?
>
> If I put two shapes containing text (text containing one spelling error)
> in the main text story and two shapes containing similar text in the
> header of a document and run this code:
>
> Sub CheckForErrors1()
> Dim pRange As Word.Range
> Dim oShp As Shape
> Dim i As Long
> For Each pRange In ActiveDocument.StoryRanges
> Do
> i = i + pRange.SpellingErrors.Count
> Set pRange = pRange.NextStoryRange
> Loop Until pRange Is Nothing
> Next
> MsgBox i
> End Sub
>
> This msgbox response is 2.
>
> The correct response should be 4 which is the results of running this
> code:
>
> Sub CheckForErrors2()
> Dim pRange As Word.Range
> Dim oShp As Shape
> Dim i As Long
> For Each pRange In ActiveDocument.StoryRanges
> Do
> Select Case pRange.StoryType
> Case 6, 7, 8, 9, 10, 11
> i = i + pRange.SpellingErrors.Count
> If pRange.ShapeRange.Count > 0 Then
> For Each oShp In pRange.ShapeRange
> If oShp.TextFrame.HasText Then
> i = i + oShp.TextFrame.TextRange.SpellingErrors.Count
> End If
> Next oShp
> End If
> Case Else
> i = i + pRange.SpellingErrors.Count
> End Select
> Set pRange = pRange.NextStoryRange
> Loop Until pRange Is Nothing
> Next
> MsgBox i
> End Sub
>
> Why do shapes in storyrange type 6, 7, 8, 9, 10 and 11 have to be treated
> separately and individually?

Either because somebody in Microsoft thought it was a good idea, or because
somebody at Microsoft forgot to add the textranges of textboxes to the
StoryRanges collection. I suspect the latter case, but that guess is based
on no specific evidence.

Because it is an established behaviour over several versions of Word, and
because there is a workaround, I think there is zero chance of getting this
behaviour changed. We simply have to live with it.


--
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup