Delete Picture from Header??

J

James Pannozzi

I had no trouble using VBA to add a bitmap picture to a
header with ...Shapes.AddPicture "SomeFile" False, True, 8, 5, 380, 90

But I can't figure out how you use VBA to delete a picture from the header.


I've tried this (from Helmut)
but it has absolutely no effect.

Dim oSct As Section
Dim oHdr As HeaderFooter
Dim oDcm As Document
Dim oShp As Shape
Set oDcm = ActiveDocument
For Each oSct In oDcm.Sections
For Each oHdr In oSct.Headers
For Each oShp In oHdr.Shapes
oHdr.Range.InlineShapes(1).Delete
Next
Next
Next

Next I tried this:
ActiveDocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range.ShapeRange
(1).Delete
but I get an error message 5941 about something not being in its collection

How exactly do you use VBA to delete a picture from a
header??????????????????

Thanks
Jim
 
J

James Pannozzi

OK, I figured it out.

I read some stuff about how you had to use .Name property
in order to delete them from headers and that sure did'nt sound right.

Also, I mistakenly said I was using AddPicture but actually I was inserting
the logos into the
headers like so (VBScript):
..Range.Fields.Add myrange1,wdFieldIncludePicture, "somepath\somefile.jpg"
True

Anyway, what worked in removing the logos from all the headers of all
sections was the following:

Dim oSct As Section
Dim oHdr As HeaderFooter
Dim oDcm As Document
Dim oShp As Shape
Set oDcm = ActiveDocument
For Each oSct In oDcm.Sections
For Each oHdr In oSct.Headers
For Each oFld In oHdr.Range.Fields
oFld.Delete
Next
Next
Next

James Pannozzi
 

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