What are the alternative ways to insert a JPEG into a document?

  • Thread starter Scott Pendleton
  • Start date
S

Scott Pendleton

The sample code I found for inserting a JPEG into a document is as follows:

Dim oWord as New Word.Application
Dim oDoc as New Word.Document
Dim oRange as Word.Range
Set oRange = oDoc.Content
oDoc.InlineShapse.AddOLEObject
DisplayAsIcon:=False,Filename:="C:\MyPhoto.jpg",Range:=oRange

Is there an alternative to InlineShape.OLEObject? Is there a "best
practices" way?

Thanks,
Scott
 
G

Graham Mayor

What's the object of the exercise? The simple expedient of recoding a macro
within Word will give you the more obvious ways of inserting an image at the
cursor eg for in line images:

Selection.InlineShapes.AddPicture FileName:= _
"D:\My Documents\My Pictures\Filenamee.jpg", LinkToFile:=False, _
SaveWithDocument:=True

or for wrapped images:

ActiveDocument.Shapes.AddPicture(Anchor:=Selection.Range, FileName:= _
"D:\My Documents\My Pictures\Filename.jpg", LinkToFile:=False, _
SaveWithDocument:=True).WrapFormat.Type = wdWrapSquare


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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
S

Scott Pendleton

Thanks. I am often asked to use Access to create a report by building a Word
document from scratch. And when it came time to insert a JPEG, I just
searched the Web for example code, and found the code I quoted previously. It
is no easy matter to build programmatically a Word document consisting of
text, tables, photos, photos in tables, etc. and to keep track of where in
the heck you are (meaning, where the insertion point is). But your answer
solves a big problem for me.

Scott
 

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