Make image same size as cell using VBA

R

Robertico

I have a template with some tables and bookmarks.
With some code i add an image to one of the bookmarks (within a cell)
Now i'd like to use VBA to make the image the same size as the cell.

Until now i have this code:

Set WordRange = WordDoc.GoTo(What:=wdGoToBookmark, Name:="image")
Set iShape = WordRange.InlineShapes.AddPicture(Filename:=rs!image,
LinkToFile:=False, SaveWithDocument:=True)

With iShape
.Height = 365.25
.Width = 486.75
End With

I'd like to replace these values with the cell format.
With this code i tried to receive the cell format.

WordRange.Cells.Height
WordRange.Cells.Width

Tried to change it this way:

With iShape
.Height = WordRange.Cells.Height
.Width = WordRange.Cells.Width
End With

But it doesn't work as wanted. Please some advice.

Thanks in advance

Robertico
 
S

Sol Apache

If you paste the image inline with text (rather than having it anchored) the
image automatically should take the cell size, but with the aspect ratio
locked (Microsoft-speak for ³in proportion²) so that the image is not
distorted. Usually the height is OK, but sometimes the width of the image is
not as wide as the cell.

Here is a brilliant macro from Jay Freeman which I used to insert logos into
a table in a header, inline with text. It might be more than you want, but
it has bits you can use for your purposes and you can adapt it:
 
R

Robertico

If you paste the image inline with text (rather than having it anchored)
the
image automatically should take the cell size, but with the aspect ratio
locked (Microsoft-speak for ³in proportion²) so that the image is not
distorted. Usually the height is OK, but sometimes the width of the image
is
not as wide as the cell.

I use a VB6 application with a database containing the image path. (using
automation)
Pasting the image is not very reliable, because you never know what's at the
clipboard.
Here is a brilliant macro from Jay Freeman which I used to insert logos
into
a table in a header, inline with text. It might be more than you want, but
it has bits you can use for your purposes and you can adapt it:

I don't understand which part to use for my problem. It adds a picture, but
doesn't set the size.
Ms Word resizes the image, depending on it's original size.
I need a fixed size.

Regards,

Robertico
 

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