embed images in word document

J

Joseph Armbruster

I currently have some code written to automate the creation of a word
document via Python. My code exists to import a bunch of static html into a
word doc, create bookmarks, etc... It all works out really nice and boils
down (mostly) to using the call below for each static html file:

selection.InsertFile(insertingfilename)

The problem is the images do not appear to be embedded in the actual word
document.

Is there something specific I need to do in order to make the InlineShape
and Shapes embedded?


Thank You,
Joseph Armbruster
 
J

Jean-Guy Marcil

Joseph Armbruster was telling us:
Joseph Armbruster nous racontait que :
I currently have some code written to automate the creation of a word
document via Python. My code exists to import a bunch of static html
into a word doc, create bookmarks, etc... It all works out really
nice and boils down (mostly) to using the call below for each static
html file:

selection.InsertFile(insertingfilename)

The problem is the images do not appear to be embedded in the actual
word document.

Is there something specific I need to do in order to make the
InlineShape and Shapes embedded?

Try something like this:

Dim i As Long

Selection.InsertFile (insertingfilename)

With ActiveDocument.Fields
For i = .Count To 1 Step -1
If InStr(1, .Item(i).Code.Text, "INCLUDEPICTURE") Then
.Item(i).Unlink
End If
Next
End With
 
J

Joseph Armbruster

I gave it a shot. There does not appear to be any fields in the word doc
with the suggested token. All the fields in my doc are hyperlinks:

examining field: HYPERLINK "" \l "training"
examining field: HYPERLINK "" \l "systemdata"
examining field: HYPERLINK "" \l "standards"
examining field: HYPERLINK "" \l "regressiontesting"
examining field: HYPERLINK "" \l "sum"
examining field: HYPERLINK "" \l "documentation"
examining field: HYPERLINK "" \l "miscandold"
 
J

Joseph Armbruster

It seems like the only way to do this is to iterate through all my inline
shapes, get the source file name from the shapes LinkFormat.SourceFullName
then add the shapes with the SaveWithDocument flag set.

This seems like a fairly dissapointing solution. Hopefully someone else can
shed some light on the topic.
 
J

Jay Freedman

Joseph said:
It seems like the only way to do this is to iterate through all my
inline shapes, get the source file name from the shapes
LinkFormat.SourceFullName then add the shapes with the
SaveWithDocument flag set.

This seems like a fairly dissapointing solution. Hopefully someone
else can shed some light on the topic.

You can do this manually in one step in the user interface: Open the Edit >
Links dialog, check the box for "Save picture in document", shift-select all
the links in the list, and click the Break Link button.

If you really want to do this with code, maybe as part of a larger macro,
you can do the same thing this way:

Sub EmbedAllLinkedPix()
Dim oILS As InlineShape
Dim oShp As Shape
Dim idx As Long

With ActiveDocument
' embed linked InlineShapes
For idx = .InlineShapes.Count To 1 Step -1
Set oILS = .InlineShapes(idx)
If Not oILS.LinkFormat Is Nothing Then
oILS.LinkFormat.SavePictureWithDocument = True
oILS.LinkFormat.BreakLink
End If
Next

' embed linked Shapes
For idx = .Shapes.Count To 1 Step -1
Set oShp = .Shapes(idx)
If Not oShp.LinkFormat Is Nothing Then
oShp.LinkFormat.SavePictureWithDocument = True
oShp.LinkFormat.BreakLink
End If
Next
End With
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 

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