Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2005

Tip: Looking for answers? Try searching our database.

Make image same size as cell using VBA

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Robertico - 03 Oct 2005 18:31 GMT
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
Sol Apache - 03 Oct 2005 21:22 GMT
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:

> Dim oRng As Range
>
[quoted text clipped - 24 lines]
>          End If
>    End With

hth

On 3/10/05 18:31, in article #rK#LBEyFHA.2676@TK2MSFTNGP10.phx.gbl,

> I have a template with some tables and bookmarks.
> With some code i add an image to one of the bookmarks (within a cell)
[quoted text clipped - 29 lines]
>
> Robertico
Robertico - 04 Oct 2005 17:51 GMT
> If you paste the image inline with text (rather than having it anchored)
> the
[quoted text clipped - 3 lines]
> 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
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.