Delete a picture in a Header

  • Thread starter Michiel Rapati-Kekkonen
  • Start date
M

Michiel Rapati-Kekkonen

I just understood how to put a picture in a header using AddPicture.
But as the name sais: it adds.
Since there is already a picture, I want it to be replaced.
But I can't get Delete to work there.
Who knows how to handle this?

TIA

Michiel Rapati
 
D

Doug Robbins - Word MVP

Hi Michiel,

The following will delete the first picture from the main header of the
first section of the document:

ActiveDocument.Sections(1).Headers(wdHeaderFooterPrimary).Range.InlineShapes
(1).Delete

Please respond to the newsgroups for the benefit of others who may be
interested.

Hope this helps
Doug Robbins - Word MVP
 
M

Michiel Rapati-Kekkonen

Thanks,
but...
not yet

it looked indeed as if it worked, when for the first time applied

This is the situation:
my document contains two different headers (first page and the rest) with
each a different picture.

I the want to cycle through different sets of pictures.

My code, enriched with the suggested code, now looks like this:
(the CycleVar is there for cycling purposes)

With ActiveDocument
'(first delete the existing picture)

..Sections(1).Headers(wdHeaderFooterFirstPage).Range.InlineShapes(1).Delete

'(then insert a picture)
.Sections(1).Headers(wdHeaderFooterFirstPage) _
.Shapes.AddPicture FileName:= "MyPic" & CycleVar & ".bmp", _
LinkToFile:=False, SaveWithDocument:=True

'(do the same for the following headers)

..Sections(1).Headers(wdHeaderFooterPrimary).Range.InlineShapes(1).Delete

.Sections(1).Headers(wdHeaderFooterPrimary) _
.Shapes.AddPicture FileName:= "MySmallPic" & CycleVar & ".bmp",
_
LinkToFile:=False, SaveWithDocument:=True

End With


when I execute it, it indeed removes/replaces the existing picture in the
header on the first page,
but, when trying to delete the picture in the following headers,
it complains about that second Delete with error 5941: the requested member
of the collection does not exist. or something like that

Experimenting with it learned that a picture put in the header by my code,
cannot be removed by this kind of Deleting.

Anybody?

Thanks anyway!

Michiel Rapati
 

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