Save Inlineshapes to disk

S

sos00

Hi guys,

i have some documents which contain many pictures (Embed pictures)...
and wanna save this pictures to disk using vba .
i didn't found any method or function in InlineShape class to do that , is
it possible and how ?

Thaks
 
J

Jezebel

Save the document as HTML. The images get saved separately. It's pretty
cludgy, but serves you right for sloppy procedure. Advice to sailors caught
on a lee shore in a storm: rule 1 - do not let yourself get caught in this
position.
 
C

Cindy M -WordMVP-

Hi Sos00,
i have some documents which contain many pictures (Embed pictures)...
and wanna save this pictures to disk using vba .
i didn't found any method or function in InlineShape class to do that , is
it possible and how ?
Word 2003 has a EnhMetaFileBits property that will pick up the information
about how the current selection is to be displayed, as an array of bytes.
VBA, alone, can't do anything with this. But using the Windows API, this can
be processed to a picture, which can be streamed to disk.

I'm not able to tell you how to do this, but someone in a classic Visual
Basic (VB) group might be able to tell you how. Usually, any Windows API code
that VB can work with can also be used in VBA.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
T

Tony Jollans

Well, you can do this with VBA alone.

The EnhMetaFileBits represent the image in bitmap format so you have to save
as a bmp. I don't know if it's possible to create any other sort of image
directly from Word.

Sub SaveImage()

Dim ImageStream As ADODB.Stream

Set ImageStream = CreateObject("ADODB.Stream")
With ImageStream
.Type = 1 ' adTypeBinary
.Open
.Write ActiveDocument.InlineShapes(1).Range.EnhMetaFileBits
.SaveToFile "C:\Image.bmp"
.Close
End With

Set ImageStream = Nothing

End Sub
 
C

Cindy M -WordMVP-

Hi Tony,
The EnhMetaFileBits represent the image in bitmap format so you have to save
as a bmp. I don't know if it's possible to create any other sort of image
directly from Word.
Ai, way cool :) Didn't know one could to this with ADO!

Just an addendum to anyone else trying to use this code who's not familiar
with ADODB: you need to set an reference (Tools/References) to a "Microsoft
ActiveX Data Object Library". Mine was set to version 2.6; I don't know from
which version on this is supported

Sub SaveImage()

Dim ImageStream As ADODB.Stream

Set ImageStream = CreateObject("ADODB.Stream")
With ImageStream
.Type = 1 ' adTypeBinary
.Open
.Write ActiveDocument.InlineShapes(1).Range.EnhMetaFileBits
.SaveToFile "C:\Image.bmp"
.Close
End With

Set ImageStream = Nothing

End Sub

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :)
 
T

Tony Jollans

Thanks Cindy,

I changed the constant so you wouldn't need the reference but forgot the
declaration :)

I think it's supported in version 2.5 and later.
 
S

sos00

Thanx guys,
it works fine...

before this solution i had to Select inline shape and then Copy that to
clipboard by using Selection.Copy and finally extract that image from
clipboard and write it to disk.
 

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