WordObject

  • Thread starter Doug Robbins - Word MVP
  • Start date
D

Doug Robbins - Word MVP

Hi Chris,

One sure way of controlling the location of the picture is to insert it into
the cell of a table. Put a one row, one column, borderless table where you
want the picture to appear and use the following code. In this example, I
am putting the picture into the second cell in the fifth row of the table
and also sizing the picture to fit the cell dimensions - while maintaining
the aspect ratio of the picture:

'Insert logo
WordDoc.Tables(1).Cell(5, 2).Range.InlineShapes.AddPicture
FileName:=Me.Logo
'Re-size logo
oheight = WordDoc.Tables(1).Cell(5, 2).Range.InlineShapes(1).Height
owidth = WordDoc.Tables(1).Cell(5, 2).Range.InlineShapes(1).Width
If oheight > 72 * 1.6 Then
With WordDoc.Tables(1).Cell(5, 2).Range.InlineShapes(1)
.Height = 72 * 1.6
.Width = owidth * 72 * 1.6 / oheight
End With
End If
If oheight < 72 * 0.68 Then
With WordDoc.Tables(1).Cell(5, 2).Range.InlineShapes(1)
.Height = 72 * 1.6
.Width = owidth * 72 * 1.6 / oheight
End With
End If
oheight = WordDoc.Tables(1).Cell(5, 2).Range.InlineShapes(1).Height
owidth = WordDoc.Tables(1).Cell(5, 2).Range.InlineShapes(1).Width
If owidth > 72 * 1.6 Then
With WordDoc.Tables(1).Cell(5, 2).Range.InlineShapes(1)
.Width = 72 * 1.6
.Height = oheight * 72 * 1.6 / owidth
End With
End If

--
Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
C

Chris

Hi,

In VB 6 I use bookmarks to specify locations to insert text and all this
seems ok except when I try to insert a picture.

I am trying to insert a picture in a specific place in a document.

The code looks like this:-

aaa.EditGoTo "picture_loc"
aaa.InsertPicture Name:=PictureLoc"

The image prints but only after the first page break in the document even
though the picture is very small.


Any help would be appreciated.

Regards

Chris
 
D

Doug Robbins - Word MVP

Hi Chris,

Does your table have 5 rows and 2 columns?

It was into the second cell on the fifth row that I was inserting the
picture. That is the reason for the .Cell(5, 2) You should change the
rownum and colnum to suit where you want to insert the picture.

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
D

Doug Robbins - Word MVP

Hi Chris,

As long as xxx refers to a document object, it should work. Note that the
email program has caused the line to wrap. The following should be all one
line of code:

xxx.Tables(1).Cell(1,1).Range.InlineShapes.AddPicture
FileName:=c:\aaa\a1.gif

Please post any further questions or followup to the newsgroups for the
benefit of others who may be interested. Unsolicited questions forwarded
directly to me will only be answered on a paid consulting basis.

Hope this helps
Doug Robbins - Word MVP
 
C

Chris

Hi,

I have not been able to get te supplied code to work.

It falls over on the line

xxx.Tables(1).Cell(5, 2).Range.InlineShapes.AddPicture
FileName:=c:\aaa\a1.gif

Note that xxx is defined as follows in the main module.

Public xxx as object

Thanks

Chris
 
C

Chris

Hi,

This is all very new to me, I tried this with a table with only one cell
with a bookmark in it.

xxx.Tables(1).Cell(1,1).Range.InlineShapes.AddPicture
FileName:=c:\aaa\a1.gif
but fails.

Note that xxx is defined as follows in the main module.
Public xxx as object

You state
WordDoc.Tables........
is this the same as
xxx.Tables.........

Note that ..............
xxx.InsertPicture Name=c:\aaa\xxx.gif appears to works but cannot get the
picture to sit in the correct place, even though I have a bookmark and run
the command

xxx.EditGoTo "bookmark_name"
prior to the xxx.InsertPicture command
 

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