Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Inserting multiple pictures into a Word table cell

1,224 views
Skip to first unread message

Mojo

unread,
Mar 28, 2010, 1:41:32 PM3/28/10
to

Hi All

My VB6 app inserts mutliple pictures into a Word doc template, but because I
don't know whether it will be 1 image (with accompanying text) or 36 images
(ditto) my idea was to just have a pre-created table of 1 row and 1 col and
then just keep inserting the pic then text in a long vertical list, eg:

Pic
title of pic
comment

Pic
title of pic
comment

Pic
title of pic
comment

etc

I've used the following code up to now:

Set oPic = oNewDoc.Tables(1).Cell(1, 1).Range.InlineShapes.AddPicture _
(MyPics & "\DCP_1960.JPG", False, True)

oPic.Width = 200
oPic.Height = 150
oNewDoc.Tables(1).Cell(1, 1).Range.Text = oNewDoc.Tables(2).Cell(2,
2).Range.Text & _
vbCrLf & "Jenny in Brid" & vbCrLf & "comments here"

But as you will probably know already, I can't add another pic to the above
code. If I do set oPic again then it overwrites the above pic and text.

Is there anyway I can concat a number of pics and text to drop into 1 cell
or have I got to have 1 cell for each pic??

Thanks


Doug Robbins - Word MVP

unread,
Mar 28, 2010, 5:24:32 PM3/28/10
to
Use a construction such as:

Dim otable As Table
Dim orow As Row
Dim ocell As Cell
Dim i As Long
Set otable = ActiveDocument.Tables(1)
'Set up a loop that iterates through all of the pictures
For i = 1 To [pictures].Count
If i = 1 Then
Set ocell = otable.Cell(1, 0)
Else
Set orow = otable.Rows.Add
Set ocell = orow.Cells(1)
End If
Set oPic = ocell.Range.InlineShapes.AddPicture _


(MyPics & "\DCP_1960.JPG", False, True)
oPic.Width = 200
oPic.Height = 150

Next i


--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com

"Mojo" <ple...@dont.spam.com> wrote in message
news:#4qu23pz...@TK2MSFTNGP05.phx.gbl...

cete...@gmail.com

unread,
Jul 21, 2016, 5:32:55 AM7/21/16
to
thanks , it works fine for me

dduf...@gmail.com

unread,
Jul 22, 2016, 1:59:10 PM7/22/16
to
> My VB6 app inserts mutliple pictures into a Word doc template, but because I
> don't know whether it will be 1 image (with accompanying text) or 36 images
> (ditto) my idea was to just have a pre-created table of 1 row and 1 col and
> then just keep inserting the pic then text in a long vertical list, eg:
>

Take a look at macropod's code http://answers.microsoft.com/en-us/office/forum/office_2013_release-customize/bulk-insert-images-into-word-table/907cc43a-8d35-408b-93f6-74a1373c96a8 to find a very useful routines to do what you ask. I made some useful modifications to suit my needs and have added the Macro to my Normal.dot so it is available to me at any time. Inserts a RowCol table of any shape in calculated space remaining between margins. Easily identify images and add all the descriptive text you want for each image.
2Dee

0 new messages