Deleting images

C

Cristiano

I have many Word file with an image (in the header or in the page, but just
one image).
I need the VBA code to delete the image (I know how to load all the .doc
files).

Thanks
Cristiano
 
C

Chuck

The following code will delete Shapes and InlineShapes throughout the
document. I'm sure there's a more efficient way of doing this but the
following is at least thorough. You can add tests to delete only certain
kinds of shapes/inlineshapes but judging from your post that isn't
necessary... HTH

Dim rngStory As Range
Dim shpShape As Shape
Dim shpInline As InlineShape
Dim hdrHeader As HeaderFooter
Dim ftrFooter As HeaderFooter
Dim x As Long

With ActiveDocument
'Delete InlineShapes from all Stories
For Each rngStory In .StoryRanges
For Each shpInline In rngStory.InlineShapes
shpInline.Delete
Next shpInline
Next rngStory
'Shapes only supported in headers/footers/body
For Each shpShape In .Shapes
shpShape.Delete
Next shpShape
For i = 1 To .Sections.Count
For Each hdrHeader In .Sections(i).Headers
For Each shpShape In hdrHeader.Shapes
shpShape.Delete
Next shpShape
Next hdrHeader
Next i
For i = 1 To .Sections.Count
For Each ftrFooter In .Sections(i).Headers
For Each shpShape In ftrFooter.Shapes
shpShape.Delete
Next shpShape
Next ftrFooter
Next i
End With
 

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