Header and Footer StoryRanges

G

Greg Maxey

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.
 
J

Jonathan West

Greg Maxey said:
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.
 

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