Log in

View Full Version : Solved: Replacing graphics with text



bobjohnson
12-04-2008, 03:51 PM
Hi,

I need to write a macro that replaces all graphics in a word document with text. The text will be the same no matter what graphic is replaced.

Originally i tried the code below, but i found that also will catch embedded excel files which I dont want. So i tried using the inlineshapes code but i cant figure out how to use that to delete the graphic and replace it with text at the same time. I got it to delete the graphic, or put some text after the graphic, but i cant get it to do both? Can anyone help?

This was my original code that would also catch embedded excel:

Sub replacegraphics()

Dim rng As Range
For Each rng In ActiveDocument.StoryRanges
Do
With rng.Find
.Text = "^g"
.Replacement.Text = "[graphic replaced]"
.Execute Replace:=wdReplaceAll
End With
Set rng = rng.NextStoryRange
Loop Until rng Is Nothing
Next rng
End Sub

TonyJollans
12-05-2008, 01:43 AM
This should do it:
For Each InSh In ActiveDocument.Range.InlineShapes
Select Case InSh.Type
Case wdInlineShapePicture, _
wdInlineShapeLinkedPicture _
' Add whatever other types you want here
InSh.Range.Text = "[o]"
End Select
Next

bobjohnson
12-05-2008, 04:20 PM
Awesome, thank you very much. Ill let you know after the weekend if it worked out!

bobjohnson
12-10-2008, 01:52 PM
Ok that didnt work out, this is what i came up with:

Sub replacegraphics()

For Each InSh In ActiveDocument.Range.InlineShapes
Select Case InSh.Type
Case wdInlineShapePicture, _
wdInlineShapeLinkedPicture, _
wdInlineShapeLinkedPictureHorizontalLine, _
wdInlineShapeHorizontalLine, _
wdInlineShapeOWSAnchor, _
wdInlineShapePictureBullet, _

InSh.Range.Text = "[o]"
End Select
Next
End Sub


I figured that would grab everything but the embedded excel, but it didnt. It actually didnt replace any of the graphics? Maybe i understood you wrong.


*edit* actually, nevermind, i realised the pictures i was trying to grab were infact pictures inside an embedded excel file, so its all good. Seems to be working ok now on the other files i have. Thanks for your help!