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!

How to remove image from a word document 1

Status
Not open for further replies.

christer99

IS-IT--Management
Dec 3, 2001
247
How do I remove any images from a Word document using Visual Basic/.NET?

I have tried this:

Dim sh As Shape
For Each sh In .ActiveDocument.Shapes
sh.Select()
.Selection.Delete()
Next sh

and the image is still there (it's an image in the main part of the document. NOT in the header or anything like that). There might be multiple images, so I ideally I would like something that would deleted all the images.

I have also tried this but it doesn't work either:

Dim piint As Integer
For piint = 1 To 200
wrdTemp.ActiveDocument.InlineShapes(i).Delete()
wrdTemp.ActiveDocument.Shapes("Picture " + CStr(piint) + "").Delete()
Next
 
Well you tried For Each as a Shape. Did you try For Each as an InlineShape?

You could also do:

Code:
    Selection.WholeStory
    With Selection.Find
        Do
        .Execute findtext:="g", Forward:=True
        Selection.Delete
        Loop Until .Found = False
    End With

This should remove ALL graphics.

Gerry
 
Ooops that should be:

findtext:="^g"

the caret is rather important!

Gerry
 
I got it work using this:

Dim intshapescount As Integer

Dim piint As Integer
intshapescount = .ActiveDocument.Shapes.Count

For piint = 1 To intshapescount

.ActiveDocument.Shapes(piint).Delete()
intshapescount = .ActiveDocument.Shapes.Count

Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top