Putting an image in a table cell

H

hals_left

I have some code (below) that creates table rows and writes data from a
database, and symbols to the new cells.

I have a small image that needs to go into each row too, If I have the
image in the first row is there anyway to put it into each new row
created ?

Thanks
hals_left

ActiveDocument.Tables(3).Rows.Add
With ActiveDocument.Tables(3).Rows(ActiveDocument.Tables(3).Rows.Count
- 1)
.Cells(1).Select
Selection.Text = objRS("ID")

.Cells(2).Select
Selection.Text = objRS("Name")


If objRS("Selected") = "1" Then
.Cells(3).Select
Selection.End = Selection.End - 1
Selection.InsertSymbol Font:="Wingdings",
CharacterNumber:=-3844, Unicode:=True
End If

' How to do this part ?
.Cells(4).Select
Selection.Contents = Copy a gif image from another table cell or
import it from file ?
 
Z

zkid

Have you tried placing the graphic in the clipboard and then just pasting it
into the current cell? If the graphic is too squirelly and doesn't paste in
the correct location, then what I do with client letterhead is create a table
with the grapic in another document, then I copy the whole table and paste it
into the needed location. Just make sure the table dimensions are the same
as the row you need to add.

Hope this helps. zkid
 
J

Jean-Guy Marcil

hals_left was telling us:
hals_left nous racontait que :
I have some code (below) that creates table rows and writes data from
a database, and symbols to the new cells.

I have a small image that needs to go into each row too, If I have the
image in the first row is there anyway to put it into each new row
created ?

Thanks
hals_left

ActiveDocument.Tables(3).Rows.Add
With ActiveDocument.Tables(3).Rows(ActiveDocument.Tables(3).Rows.Count
- 1)
.Cells(1).Select
Selection.Text = objRS("ID")

.Cells(2).Select
Selection.Text = objRS("Name")


If objRS("Selected") = "1" Then
.Cells(3).Select
Selection.End = Selection.End - 1
Selection.InsertSymbol Font:="Wingdings",
CharacterNumber:=-3844, Unicode:=True
End If

' How to do this part ?
.Cells(4).Select
Selection.Contents = Copy a gif image from another table cell or
import it from file ?

The easiest by far would be to store the Image as an AutoText entry in the
Attached Template if there is one.
Make sure that the AutoText entry has a unique name.
Also, try to avoid using the Selection object. The Range object is faster
and more reliable:

'_______________________________________
Dim TargetTable As Table

Set TargetTable = ActiveDocument.Tables(3)

With TargetTable
.Rows.Add

With .Rows(TargetTable.Rows.Count - 1)
.Cells(1).Range.Text = objRS("ID")

.Cells(2).Range.Text = objRS("Name")

If objRS("Selected") = "1" Then
With .Cells(3).Range
.Collapse wdCollapseStart
.InsertSymbol CharacterNumber:=-3844, _
Font:="Wingdings", Unicode:=True
End With
End If

' How to do this part ?
With .Cells(4).Range
.Text = "Name of AutoText Entry"
.MoveEnd wdCharacter, -1
.InsertAutoText
End With
'Selection.Contents = Copy a gif image from another table cell or
'import it from file ?
End With

End With
'_______________________________________

If the autotext way in not possible, try this version which assumes that the
image already exists in the fourth cell of the second row.

'_______________________________________
Dim TargetTable As Table
Dim SourceRange As Range

Set TargetTable = ActiveDocument.Tables(3)

With TargetTable
.Rows.Add

With .Rows(TargetTable.Rows.Count - 1)
.Cells(1).Range.Text = objRS("ID")

.Cells(2).Range.Text = objRS("Name")

If objRS("Selected") = "1" Then
With .Cells(3).Range
.Collapse wdCollapseStart
.InsertSymbol CharacterNumber:=-3844, _
Font:="Wingdings", Unicode:=True
End With
End If

' How to do this part ?
Set SourceRange = TargetTable.Cell(2, 4).Range
SourceRange.MoveEnd wdCharacter, -1
.Cells(4).Range.FormattedText = SourceRange

'Selection.Contents = Copy a gif image from another table cell or
'import it from file ?
End With

End With
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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