G
Greg Maxey
Last night I stumbled on what I consider odd behaviour while using VBA to
delete shapes in a document header. I had a multi-section document with
headers unlinked and first page, odd/even headers. All together there aret
15 shapes in the various headers.
It appears to me that the following code should only process and delete
shapes that are in the primary header of section 3. What I consider odd is
that it processes all shapes in all sections and all header types (i.e., it
deletes all 15 shapes)
Sub Test()
Dim oShp As Shape
For Each oShp In ActiveDocument.Sections(3).Headers(3).Shapes
oShp.Delete
Next
End Sub
The same thing happens if I change the Section and Headers index to "1."
I ran this code:
Sub Scratchmacro()
MsgBox ActiveDocument.Sections(2).Headers(1).Shapes.Count
End Sub
I expected a return of 2 which is how many shapes are in fact in Section 2
firstpage header but the result I got was 15!!
I scratched up this code which does process only the designated header, but
I don't understand what is happenning in the code above. Thanks for any
explanation you may provide.
Sub Test2()
Dim oRng As Word.Range
Dim oShp As Shape
Set oRng = ActiveDocument.Sections(3).Headers(3).Range
For Each oShp In oRng.ShapeRange
oShp.Delete
Next
End Sub
delete shapes in a document header. I had a multi-section document with
headers unlinked and first page, odd/even headers. All together there aret
15 shapes in the various headers.
It appears to me that the following code should only process and delete
shapes that are in the primary header of section 3. What I consider odd is
that it processes all shapes in all sections and all header types (i.e., it
deletes all 15 shapes)
Sub Test()
Dim oShp As Shape
For Each oShp In ActiveDocument.Sections(3).Headers(3).Shapes
oShp.Delete
Next
End Sub
The same thing happens if I change the Section and Headers index to "1."
I ran this code:
Sub Scratchmacro()
MsgBox ActiveDocument.Sections(2).Headers(1).Shapes.Count
End Sub
I expected a return of 2 which is how many shapes are in fact in Section 2
firstpage header but the result I got was 15!!
I scratched up this code which does process only the designated header, but
I don't understand what is happenning in the code above. Thanks for any
explanation you may provide.
Sub Test2()
Dim oRng As Word.Range
Dim oShp As Shape
Set oRng = ActiveDocument.Sections(3).Headers(3).Range
For Each oShp In oRng.ShapeRange
oShp.Delete
Next
End Sub