Jean-Guy
Thu Oct 27 13:26:04 CDT 2005
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
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site:
http://www.word.mvps.org