VBA graphics and tables

R

Roger Hembury

Hi,

Wonder if you can help.

I am using VB6 to control Word 2002 via the oject model but I can't get the
syntax quite right to insert a jpg graphic into a specific cell in a table.

If I just dump the graphic on the page then the code

objWord.ActiveDocument.Shapes.AddPicture App.Path & "\" & DataExch.Logo,
True, True, 210, 230, 177, 99

works but it can be a bit haphazard where the graphic ends up due to the
other text on the page.

What I need is a similar line of code the plonk the graphic into a table
cell.

Thanks in advance

Roger
 
R

Roger Hembury

Jonathan - thanks for your input :)

I can now get the picture into the table cell using

objWord.Application.ActiveDocument.Tables(1).Cell(2,
1).Range.InlineShapes.AddPicture App.Path & "\" & DataExch.Logo, False, True

but I now have another little problem - the image displayed is tiny and is
in the top left hand corner of the cell - how can I get the image back to
its original size and centered in the middle of the cell?

Thanks

Roger
 
R

Roger Hembury

UPDATE.

I have sorted out the problem with centering the image and I can resize the
image using scaleheight and scalewidth using a value of 1000 to get it back
to a decent size but I am not sure if this is the correct method or the
safest way to do it.

Roger
 
J

Jonathan West

Roger Hembury said:
UPDATE.

I have sorted out the problem with centering the image and I can resize
the image using scaleheight and scalewidth using a value of 1000 to get
it back to a decent size but I am not sure if this is the correct method
or the safest way to do it.

Roger

That's one way. Another would be to set the Width property to be a suitable
value - perhaps the cell width minus a bit.
 
R

Roger Hembury

Hi,

Finally got this sorted and thought I would share the code with the rest of
the group -

objWord.Application.ActiveDocument.Tables(1).Cell(7,
1).VerticalAlignment = wdCellAlignVerticalCenter
objWord.Application.ActiveDocument.Tables(1).Cell(7,
1).Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
objWord.Application.ActiveDocument.Tables(1).Cell(7,
1).Range.InlineShapes.AddPicture App.Path & "\" & DataExch.Logo, False, True

objWord.Application.ActiveDocument.Tables(1).Cell(7,
1).Range.InlineShapes(1).LockAspectRatio = msoTrue
objWord.Application.ActiveDocument.Tables(1).Cell(7,
1).Range.InlineShapes(1).Height = 130
objWord.Application.ActiveDocument.Tables(1).Cell(7,
1).Range.InlineShapes(1).Width = 200

I just forced the height and width of the image and let Word sort out the
resizing of the image as it's only a logo on the front page of a report.

Thanks for you help Jonathan.

Regards

Roger
 
J

Jonathan West

Hi Roger,

You can make the code a bit more readable like this

With objWord.Application.ActiveDocument.Tables(1).Cell(7, 1)
.VerticalAlignment = wdCellAlignVerticalCenter
.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter
.Range.InlineShapes.AddPicture App.Path & "\" & DataExch.Logo, False, True
.Range.InlineShapes(1).LockAspectRatio = msoTrue
.Range.InlineShapes(1).Height = 130
.Range.InlineShapes(1).Width = 200
End With
 

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