Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting shapes in header & footer for 1 section only

Status
Not open for further replies.

AMJZ

Technical User
Nov 17, 2004
6
GB
Hi all.
I'm trying to delete all shapes for a specific section of a word document. I've set LinkToPrevious to false for all sections and then I do the loop below. The problem is that the For loop below runs on and deletes all shapes in all sections, and that happens whether section breaks are Nextpage or Continuous types.

How can I stop the loop going beyond the end of a section?

With ActiveDocument.Sections(1)
For Each shp In .Headers(wdHeaderFooterFirstPage).Shapes
shp.Delete
Next shp
End With
 
Sorry - As you can probably see, I forgot to specify that I'm only trying to delete shapes in the header and footer for the section.
AMJZ.
 
Hi. Have you fine with this, or are you still looking for some information?

Gerry
 
Cheers Gerry.
Well I sort of gave up but Yes, I'm still looking for help. Perhaps I was not very clear. I am trying to delete all shapes in the header and footer for only a single section of the word document, but what happens is that the shapes in headers and footers for all sections get deleted. The original code is still relevant.

What I need is some extra test for the end of a section and then to quit the loop.

Thanks for your interest - AMJZ.
 
Code:
Sub DeleteHeader_InlineShapes()
Dim mInLineShape As InlineShape
Dim r As Range
Set r = ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range
For Each mInLineShape In r.InlineShapes
    mInLineShape.Delete
Next
Set r = Nothing
End Sub

Please be careful with what you are using for header objects. I notice that you are using wdHeaderFooterFirstPage. This action would NOT remove any shapes from HeaderFooterPrimary, which is....Primary.

Also, are you completely sure that you need to action Shapes, rather than InLineShapes?

Gerry
 
I've finally got back to this task and your stuff does the business.
Thanks a lot Gerry for your help - AMJZ.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top