Copy Paste Text with Image

  • Thread starter Philip L Jackson
  • Start date
P

Philip L Jackson

Hi

Additional problem following on from my hyperlink question....

I have a customer with many 1000's of product descriptions in plain text
documents.

I have a small application whch can take these and copy/paste the text into
separate word documents. However the text includes paths to images and
I wish to replace these into word with the image but cannot work out how to
do
this.

Any advice greatfully appreciated.

Regards
PLJ
 
G

Graham Mayor

Having pasted the text into the document and assuming the paths are in the
format

D:\My Documents\My Pictures\Filename.jpg

the following macro will convert all those filenames to images (provided
they are on the D drive and are jpg format - if not change the drive letter
and extension). The images will be inserted at their original size curtailed
by the width between the current margins.

Sub ReplaceWithIncludePictureField()
Dim strFind As String
strFind = strFind & "D:\\*.jpg"
With Selection
.HomeKey wdStory
With .Find
.ClearFormatting
.Replacement.ClearFormatting
Do While .Execute(findText:=strFind, _
Wrap:=wdFindStop, Forward:=True, _
MatchWildcards:=True) = True
With Selection
sText = Selection.Range.Text
sText = Replace(sText, "\", "\\")
sText = Chr(34) & sText & Chr(34)
.Fields.Add Range:=Selection.Range, _
Type:=wdFieldIncludePicture, Text:= _
sText, PreserveFormatting:=False
Selection.Collapse wdCollapseEnd
End With
Loop
End With
End With
ActiveDocument.Fields.Update
ActiveWindow.View.ShowFieldCodes = False
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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