Deleting Shapes in Document Header

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
 
H

Helmut Weber

Hi Greg,

you are not alone,
though I would have known that you have to use shaperange,
just from experience,
yet, I've never understood why.

--
Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Win XP, Office 2003
"red.sys" & Chr$(64) & "t-online.de"
 
R

Russ

Greg and Helmut,
A difference between graphics memory location and text memory location?
Could it be that shaperange addresses the graphics layer or the memory set
aside for graphics more precisely with its pointers into memory?
 

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